Skip to content

Commit a24ecd3

Browse files
committed
feat(SegmentedSwitch): add ariaLabel and ariaLabelledby props
1 parent 967c9fa commit a24ecd3

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

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

+12-10
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,18 @@ const Component = () => {
3030

3131
_Table below contains all types of the props available in the SegmentedSwitch component._
3232

33-
| Name | Type | Default | Description |
34-
| :---------- | :-------------------------------------------- | :------ | :---------------------------------- |
35-
| dataTest | `string` | | Optional prop for testing purposes. |
36-
| help | `React.Node` | | Optional help message. |
37-
| error | `React.Node` | | Optional error message. |
38-
| options | [`Option[]`](#option) | | Array of options. |
39-
| onChange | `(ev: ChangeEvent<HTMLInputElement>) => void` | | Function for handling change event. |
40-
| onFocus | `(ev: FocusEvent<HTMLInputElement>) => void` | | Function for handling focus event. |
41-
| label | `string` | | Label of the component. |
42-
| showTooltip | `boolean` | `false` | Show tooltip. |
33+
| Name | Type | Default | Description |
34+
| :------------- | :-------------------------------------------- | :------ | :--------------------------------------------------------------------------------------------- |
35+
| dataTest | `string` | | Optional prop for testing purposes. |
36+
| help | `React.Node` | | Optional help message. |
37+
| error | `React.Node` | | Optional error message. |
38+
| options | [`Option[]`](#option) | | Array of options. |
39+
| onChange | `(ev: ChangeEvent<HTMLInputElement>) => void` | | Function for handling change event. |
40+
| onFocus | `(ev: FocusEvent<HTMLInputElement>) => void` | | Function for handling focus event. |
41+
| label | `string` | | Label of the component. |
42+
| ariaLabel | `string` | | Optional `aria-label` attribute. |
43+
| ariaLabelledby | `string` | | Optional `aria-labelledby` attribute. Receives an id of the element that labels the component. |
44+
| showTooltip | `boolean` | `false` | Show tooltip. |
4345

4446
## Option
4547

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const meta: Meta<typeof SegmentedSwitch> = {
1414
parameters: {
1515
info: "SegmentedSwitch component. Check Orbit.Kiwi for more detailed guidelines.",
1616
controls: {
17-
exclude: ["onChange", "onFocus"],
17+
exclude: ["onChange", "onFocus", "ariaLabel", "ariaLabelledby"],
1818
},
1919
},
2020

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const SegmentedSwitch = ({
2222
help,
2323
error,
2424
label,
25+
ariaLabel,
26+
ariaLabelledby,
2527
}: Props) => {
2628
const hasTooltip = Boolean(error || help);
2729

@@ -47,7 +49,8 @@ const SegmentedSwitch = ({
4749
)}
4850
style={{ maxWidth }}
4951
role="group"
50-
aria-label={label}
52+
aria-label={ariaLabel || label}
53+
aria-labelledby={ariaLabelledby}
5154
>
5255
{label && (
5356
<FormLabel

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

+2
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ export interface Props extends Common.Globals, Common.SpaceAfter {
2222
readonly help?: React.ReactNode;
2323
readonly label?: string;
2424
readonly options: Option[];
25+
readonly ariaLabel?: string;
26+
readonly ariaLabelledby?: string;
2527
}

0 commit comments

Comments
 (0)