Skip to content

Commit 9bb87bf

Browse files
Dinesht04LinkinStars
authored andcommitted
feat(ui): add min values for inputs and context-based keyboards for inputs
1 parent 59df184 commit 9bb87bf

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed

ui/src/components/SchemaForm/components/Input.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ interface Props {
2929
onChange?: (fd: Type.FormDataType) => void;
3030
formData: Type.FormDataType;
3131
readOnly: boolean;
32+
minValue?: number;
33+
inputMode?:
34+
| 'text'
35+
| 'search'
36+
| 'none'
37+
| 'tel'
38+
| 'url'
39+
| 'email'
40+
| 'numeric'
41+
| 'decimal'
42+
| undefined;
3243
}
3344
const Index: FC<Props> = ({
3445
type = 'text',
@@ -37,6 +48,8 @@ const Index: FC<Props> = ({
3748
onChange,
3849
formData,
3950
readOnly = false,
51+
minValue = 0,
52+
inputMode = 'text',
4053
}) => {
4154
const fieldObject = formData[fieldName];
4255
const handleChange = (evt: React.ChangeEvent<HTMLInputElement>) => {
@@ -60,6 +73,8 @@ const Index: FC<Props> = ({
6073
placeholder={placeholder}
6174
type={type}
6275
value={fieldObject?.value || ''}
76+
min={minValue}
77+
inputMode={inputMode}
6378
onChange={handleChange}
6479
disabled={readOnly}
6580
isInvalid={fieldObject?.isInvalid}

ui/src/components/SchemaForm/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,9 @@ const SchemaForm: ForwardRefRenderFunction<FormRef, FormProps> = (
368368
{widget === 'input' ? (
369369
<Input
370370
type={uiOpt && 'inputType' in uiOpt ? uiOpt.inputType : 'text'}
371+
inputMode={
372+
uiOpt && 'inputMode' in uiOpt ? uiOpt.inputMode : 'text'
373+
}
371374
placeholder={
372375
uiOpt && 'placeholder' in uiOpt ? uiOpt.placeholder : ''
373376
}

ui/src/components/SchemaForm/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ export interface InputOptions extends BaseUIOptions {
8888
| 'time'
8989
| 'url'
9090
| 'week';
91+
inputMode?:
92+
| 'text'
93+
| 'search'
94+
| 'none'
95+
| 'tel'
96+
| 'url'
97+
| 'email'
98+
| 'numeric'
99+
| 'decimal'
100+
| undefined;
91101
}
92102
export interface SelectOptions extends BaseUIOptions {}
93103
export interface UploadOptions extends BaseUIOptions {

ui/src/pages/Admin/Privileges/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ const Index: FC = () => {
9090
}
9191
return true;
9292
},
93+
inputType: 'number',
94+
inputMode: 'numeric',
9395
},
9496
};
9597
});

ui/src/pages/Admin/Write/index.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ const Index: FC = () => {
261261
<Form.Label>{t('min_tags.label')}</Form.Label>
262262
<Form.Control
263263
type="number"
264+
inputMode="numeric"
265+
min={0}
264266
value={formData.min_tags.value}
265267
isInvalid={formData.min_tags.isInvalid}
266268
onChange={(evt) => {
@@ -302,6 +304,8 @@ const Index: FC = () => {
302304
<Form.Label>{t('min_content.label')}</Form.Label>
303305
<Form.Control
304306
type="number"
307+
inputMode="numeric"
308+
min={0}
305309
value={formData.min_content.value}
306310
isInvalid={formData.min_content.isInvalid}
307311
onChange={(evt) => {
@@ -344,6 +348,8 @@ const Index: FC = () => {
344348
<Form.Label>{t('image_size.label')}</Form.Label>
345349
<Form.Control
346350
type="number"
351+
inputMode="numeric"
352+
min={0}
347353
value={formData.max_image_size.value}
348354
isInvalid={formData.max_image_size.isInvalid}
349355
onChange={(evt) => {
@@ -366,6 +372,8 @@ const Index: FC = () => {
366372
<Form.Label>{t('attachment_size.label')}</Form.Label>
367373
<Form.Control
368374
type="number"
375+
inputMode="numeric"
376+
min={0}
369377
value={formData.max_attachment_size.value}
370378
isInvalid={formData.max_attachment_size.isInvalid}
371379
onChange={(evt) => {
@@ -388,6 +396,8 @@ const Index: FC = () => {
388396
<Form.Label>{t('image_megapixels.label')}</Form.Label>
389397
<Form.Control
390398
type="number"
399+
inputMode="numeric"
400+
min={0}
391401
isInvalid={formData.max_image_megapixel.isInvalid}
392402
value={formData.max_image_megapixel.value}
393403
onChange={(evt) => {

0 commit comments

Comments
 (0)