Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: input mode for number type #3867

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@sanity/form-builder/src/inputs/NumberInput.tsx
Expand Up @@ -43,7 +43,7 @@ const NumberInput = React.forwardRef(function NumberInput(
<TextInput
type="number"
step="any"
inputMode={onlyPositiveNumber ? 'numeric' : 'text'}
inputMode={onlyPositiveNumber ? 'decimal' : 'text'}
id={id}
customValidity={errors && errors.length > 0 ? errors[0].item.message : ''}
value={value}
Expand Down
Expand Up @@ -20,7 +20,7 @@ const dummyDocument = {
_rev: '5hb8s6-k75-ip4-4bq-5ztbf3fbx',
_type: 'numberFieldTest',
_updatedAt: '2021-11-05T12:34:29Z',
num: 0,
num: 1,
title: 'Hello world',
}

Expand All @@ -45,4 +45,48 @@ describe('number-input', () => {
expect(input.value).toBe('1.2')
expect(input.checkValidity()).toBe(true)
})

it('renders inputMode equals text if there is no min rule', () => {
const {inputContainer} = renderInput('input-num')
const input = inputContainer.querySelector('input')

input.value = '1.2'
expect(input.inputMode).toBe('text')
})

it.skip('renders inputMode equals "decimal" if there ', () => {
const customSchema = Schema.compile({
name: 'test',
types: [
{
name: 'book',
type: 'document',
fields: [
{
name: 'num',
title: 'Number',
type: 'number',
/**
* For some reason this throw an error:
*
* Uncaught [Error: Schema type "number"'s `validation` was not run though `inferFromSchema`]
*/
validation: (Rule) => Rule.min(0),
},
],
},
],
})

const customDocumentType = customSchema.get('book')

const testId = 'input-num'

const {inputContainer} = inputTester(dummyDocument, customDocumentType, customSchema, testId)

const input = inputContainer.querySelector('input')

input.value = '1.2'
expect(input.inputMode).toBe('decimal')
})
})