Skip to content

Commit 1bf0bb9

Browse files
committed
feat(InputField): add ariaLabel prop
1 parent f051373 commit 1bf0bb9

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

packages/orbit-components/src/InputField/InputField.stories.tsx

+15
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ export const Playground: Story = {
489489
autoComplete: "off",
490490
id: "ID",
491491
spaceAfter: SPACINGS_AFTER.MEDIUM,
492+
ariaLabel: "Input field",
492493
},
493494

494495
argTypes: {
@@ -499,6 +500,20 @@ export const Playground: Story = {
499500
},
500501
},
501502
},
503+
504+
parameters: {
505+
controls: {
506+
exclude: [
507+
"onChange",
508+
"onFocus",
509+
"onBlur",
510+
"onMouseUp",
511+
"onMouseDown",
512+
"onSelect",
513+
"onKeyDown",
514+
],
515+
},
516+
},
502517
};
503518

504519
export const Rtl: Story = {

packages/orbit-components/src/InputField/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ The table below contains all types of props available in the InputField componen
6363
| 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). |
6464
| 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). |
6565
| 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). |
66+
| ariaLabel | `string` | | Optional prop for `aria-label` value. [See Accessibility](#accessibility). |
6667

6768
### enum
6869

@@ -134,3 +135,6 @@ class Component extends React.PureComponent<Props> {
134135
id="NICEID"
135136
/>
136137
```
138+
139+
- 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.
140+
- If the `label` prop is not provided, the `ariaLabel` prop must be specified to ensure component accessibility.

packages/orbit-components/src/InputField/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ const InputField = React.forwardRef<HTMLInputElement, Props>((props, ref) => {
110110
readOnly,
111111
list,
112112
autoComplete,
113+
ariaLabel,
113114
ariaAutocomplete,
114115
ariaActiveDescendant,
115116
ariaHasPopup,
@@ -269,7 +270,7 @@ const InputField = React.forwardRef<HTMLInputElement, Props>((props, ref) => {
269270
ref={ref}
270271
tabIndex={tabIndex !== undefined ? Number(tabIndex) : undefined}
271272
list={list}
272-
aria-labelledby={!label ? inputId : undefined}
273+
aria-label={ariaLabel}
273274
aria-describedby={shown ? `${inputId}-feedback` : undefined}
274275
aria-invalid={error ? true : undefined}
275276
aria-autocomplete={ariaAutocomplete}

packages/orbit-components/src/InputField/types.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export interface Props extends Common.Globals, Common.SpaceAfter, Common.DataAtt
5050
readonly onMouseDown?: React.MouseEventHandler<HTMLInputElement>;
5151
readonly onKeyDown?: React.KeyboardEventHandler<HTMLInputElement>;
5252
readonly onKeyUp?: React.KeyboardEventHandler<HTMLInputElement>;
53+
readonly ariaLabel?: string;
5354
readonly ariaAutocomplete?: AriaAutoComplete;
5455
readonly ariaActiveDescendant?: string;
5556
readonly ariaHasPopup?: boolean;

0 commit comments

Comments
 (0)