Skip to content

Commit

Permalink
feat(InputField): add ariaLabel prop
Browse files Browse the repository at this point in the history
  • Loading branch information
sarkaaa authored and DSil committed Dec 19, 2024
1 parent ab5d721 commit cfb5707
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/orbit-components/src/InputField/InputField.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ export const Playground: Story = {
autoComplete: "off",
id: "ID",
spaceAfter: SPACINGS_AFTER.MEDIUM,
ariaLabel: "Input field",
},

argTypes: {
Expand All @@ -499,6 +500,20 @@ export const Playground: Story = {
},
},
},

parameters: {
controls: {
exclude: [
"onChange",
"onFocus",
"onBlur",
"onMouseUp",
"onMouseDown",
"onSelect",
"onKeyDown",
],
},
},
};

export const Rtl: Story = {
Expand Down
4 changes: 4 additions & 0 deletions packages/orbit-components/src/InputField/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ The table below contains all types of props available in the InputField componen
| ariaHasPopup | `boolean` | | The aria-haspopup attribute of the input, see [this docs](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-haspopup). |
| ariaExpanded | `boolean` | | The aria-expanded attribute of the input, see [this docs](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-expanded). |
| ariaControls | `string` | | The aria-controls attribute of the input, see [this docs](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-controls). |
| ariaLabel | `string` | | Optional prop for `aria-label` value. [See Accessibility](#accessibility). |

### enum

Expand Down Expand Up @@ -134,3 +135,6 @@ class Component extends React.PureComponent<Props> {
id="NICEID"
/>
```

- The `ariaLabel` prop allows you to specify an `aria-label` attribute for the InputField component. This attribute provides additional information to screen readers, enhancing the accessibility of the component. By using `ariaLabel`, you can ensure that users who rely on assistive technologies receive the necessary context and information about the component's purpose and functionality.
- If the `label` prop is not provided, the `ariaLabel` prop must be specified to ensure component accessibility.
3 changes: 2 additions & 1 deletion packages/orbit-components/src/InputField/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const InputField = React.forwardRef<HTMLInputElement, Props>((props, ref) => {
readOnly,
list,
autoComplete,
ariaLabel,
ariaAutocomplete,
ariaActiveDescendant,
ariaHasPopup,
Expand Down Expand Up @@ -269,7 +270,7 @@ const InputField = React.forwardRef<HTMLInputElement, Props>((props, ref) => {
ref={ref}
tabIndex={tabIndex !== undefined ? Number(tabIndex) : undefined}
list={list}
aria-labelledby={!label ? inputId : undefined}
aria-label={ariaLabel}
aria-describedby={shown ? `${inputId}-feedback` : undefined}
aria-invalid={error ? true : undefined}
aria-autocomplete={ariaAutocomplete}
Expand Down
1 change: 1 addition & 0 deletions packages/orbit-components/src/InputField/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface Props extends Common.Globals, Common.SpaceAfter, Common.DataAtt
readonly onMouseDown?: React.MouseEventHandler<HTMLInputElement>;
readonly onKeyDown?: React.KeyboardEventHandler<HTMLInputElement>;
readonly onKeyUp?: React.KeyboardEventHandler<HTMLInputElement>;
readonly ariaLabel?: string;
readonly ariaAutocomplete?: AriaAutoComplete;
readonly ariaActiveDescendant?: string;
readonly ariaHasPopup?: boolean;
Expand Down

0 comments on commit cfb5707

Please sign in to comment.