Skip to content

Commit 53ac2c2

Browse files
authored
[GH-2090] [fluent-ui] fix: Text inputs render with invalid attribute (#2206)
TextWidget generated `<input type="string" ... >` HTML which is invalid as per https://html.spec.whatwg.org/multipage/input.html#states-of-the-type-attribute `<input type="text" ... >` would be apropriate. The generation of invalid HTML results in undefined behaviour. I got on the trail of the issue, because [testing-library/user-event](https://github.com/testing-library/user-event#typeelement-text-options) acted in strange ways. This PR results in the generation of valid HTML and updates the tests. fix #2090
1 parent 6f3c4c7 commit 53ac2c2

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

packages/fluent-ui/src/TextWidget/TextWidget.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ const TextWidget = ({
6969
}: React.FocusEvent<HTMLInputElement>) => onFocus(id, value);
7070

7171
const uiProps = _pick(options.props || {}, allowedProps);
72+
const inputType = schema.type === 'string' ? 'text' : `${schema.type}`
73+
7274
return (
7375
<TextField
7476
id={id}
@@ -78,7 +80,7 @@ const TextWidget = ({
7880
disabled={disabled}
7981
readOnly={readonly}
8082
name={name}
81-
type={schema.type as string}
83+
type={inputType as string}
8284
value={value ? value : ""}
8385
onChange={_onChange as any}
8486
onBlur={_onBlur}

packages/fluent-ui/test/__snapshots__/Array.test.tsx.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ exports[`array fields fixed array 1`] = `
258258
onInput={[Function]}
259259
readOnly={false}
260260
required={true}
261-
type="string"
261+
type="text"
262262
value=""
263263
/>
264264
</div>

packages/fluent-ui/test/__snapshots__/Form.test.tsx.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ exports[`single fields string field regular 1`] = `
387387
onFocus={[Function]}
388388
onInput={[Function]}
389389
readOnly={false}
390-
type="string"
390+
type="text"
391391
value=""
392392
/>
393393
</div>

packages/fluent-ui/test/__snapshots__/Object.test.tsx.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ exports[`object fields object 1`] = `
5959
onInput={[Function]}
6060
readOnly={false}
6161
required={false}
62-
type="string"
62+
type="text"
6363
value=""
6464
/>
6565
</div>

0 commit comments

Comments
 (0)