Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Commit

Permalink
[rjsf-teamGH-2090] [fluent-ui] fix: Text inputs render with invalid a…
Browse files Browse the repository at this point in the history
…ttribute (rjsf-team#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 rjsf-team#2090
  • Loading branch information
mdornseif committed Jan 26, 2021
1 parent 6f3c4c7 commit 53ac2c2
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/fluent-ui/src/TextWidget/TextWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ const TextWidget = ({
}: React.FocusEvent<HTMLInputElement>) => onFocus(id, value);

const uiProps = _pick(options.props || {}, allowedProps);
const inputType = schema.type === 'string' ? 'text' : `${schema.type}`

return (
<TextField
id={id}
Expand All @@ -78,7 +80,7 @@ const TextWidget = ({
disabled={disabled}
readOnly={readonly}
name={name}
type={schema.type as string}
type={inputType as string}
value={value ? value : ""}
onChange={_onChange as any}
onBlur={_onBlur}
Expand Down
2 changes: 1 addition & 1 deletion packages/fluent-ui/test/__snapshots__/Array.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ exports[`array fields fixed array 1`] = `
onInput={[Function]}
readOnly={false}
required={true}
type="string"
type="text"
value=""
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/fluent-ui/test/__snapshots__/Form.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ exports[`single fields string field regular 1`] = `
onFocus={[Function]}
onInput={[Function]}
readOnly={false}
type="string"
type="text"
value=""
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/fluent-ui/test/__snapshots__/Object.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ exports[`object fields object 1`] = `
onInput={[Function]}
readOnly={false}
required={false}
type="string"
type="text"
value=""
/>
</div>
Expand Down

0 comments on commit 53ac2c2

Please sign in to comment.