Skip to content

Commit

Permalink
feat: add missing autoFocus from TextField
Browse files Browse the repository at this point in the history
* fix: add missing autoFocus from TextField

* docs: add a11y docs for TextField autofocus
  • Loading branch information
jordankoschei-okta authored Mar 29, 2023
1 parent 092bafd commit d01dcd4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/odyssey-react-mui/src/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ import {
} from "./";

export type TextFieldProps = {
/**
* If `true`, the component will receive focus automatically.
*/
autoFocus?: boolean;
/**
* This prop helps users to fill forms faster, especially on mobile devices.
* The name can be confusing, as it's more like an autofill.
Expand Down Expand Up @@ -126,6 +130,7 @@ const TextField = forwardRef<HTMLInputElement, TextFieldProps>(
(
{
autoCompleteType,
autoFocus,
endAdornment,
errorMessage,
hint,
Expand Down Expand Up @@ -187,6 +192,8 @@ const TextField = forwardRef<HTMLInputElement, TextFieldProps>(
{hint && <FormHelperText id={hintId}>{hint}</FormHelperText>}
<InputBase
autoComplete={autoCompleteType}
/* eslint-disable-next-line jsx-a11y/no-autofocus */
autoFocus={autoFocus}
endAdornment={
type === "password" ? (
<InputAdornment position="end">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,9 @@ Finally, Users with low digital literacy may not understand the purpose or behav
### Purpose

When collecting an individual's personal data, you must define the input's purpose via the `autocomplete` attribute. This allows users to automate the filling of fields and ensures the purpose is known, regardless of the label. A complete list of fields this is required for may be found <a href="https://www.w3.org/TR/WCAG21/#input-purposes">in the WCAG spec</a>.

### Autofocus

Except for very specific cases, we advise against using the `autoFocus` prop; unless used considerately, the sense of focus being "teleported" to an unexpected part of the page can be jarring to users, especially those using screen readers.

More details can be found [on MDN's `autofocus` page](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus#accessibility_considerations).
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const storybookMeta: ComponentMeta<typeof TextField> = {
control: "text",
defaultValue: "name",
},
autoFocus: {
control: "boolean",
defaultValue: false,
},
isDisabled: {
control: "boolean",
defaultValue: false,
Expand Down

0 comments on commit d01dcd4

Please sign in to comment.