Skip to content

Commit 9135fe5

Browse files
committed
feat: add aria attributes and docs
1 parent 323b87e commit 9135fe5

File tree

2 files changed

+111
-3
lines changed

2 files changed

+111
-3
lines changed

src/Shared/Components/SelectPicker/SelectPicker.component.tsx

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,92 @@ import {
1717
} from './common'
1818
import { SelectPickerOptionType, SelectPickerProps } from './type'
1919

20+
/**
21+
* Generic component for select picker
22+
*
23+
* @example With icon in control
24+
* ```tsx
25+
* <SelectPicker ... icon={<CustomIcon />} />
26+
* ```
27+
*
28+
* @example Medium menu list width
29+
* ```tsx
30+
* <SelectPicker ... menuSize={ComponentSizeType.medium} />
31+
* ```
32+
*
33+
* @example Large menu list width
34+
* ```tsx
35+
* <SelectPicker ... menuSize={ComponentSizeType.large} />
36+
* ```
37+
*
38+
* @example Required label
39+
* ```tsx
40+
* <SelectPicker ... required label="Label" />
41+
* ```
42+
*
43+
* @example Custom label
44+
* ```tsx
45+
* <SelectPicker ... label={<div>Label</div>} />
46+
* ```
47+
*
48+
* @example Error state
49+
* ```tsx
50+
* <SelectPicker ... error="Something went wrong" />
51+
* ```
52+
*
53+
* @example Custom label
54+
* ```tsx
55+
* <SelectPicker ... label={<div>Label</div>} />
56+
* ```
57+
*
58+
* @example Helper text
59+
* ```tsx
60+
* <SelectPicker ... helperText="Help information" />
61+
* ```
62+
*
63+
* @example Menu list footer
64+
* The footer is sticky by default
65+
* ```tsx
66+
* <SelectPicker
67+
* ...
68+
* renderMenuListFooter={() => (
69+
* <div className="px-8 py-6 dc__border-top bcn-50 cn-6">
70+
* <div>Foot note</div>
71+
* </div>
72+
* )}
73+
* />
74+
* ```
75+
*
76+
* @example Loading state
77+
* ```tsx
78+
* <SelectPicker ... isLoading />
79+
* ```
80+
*
81+
* @example Disabled state
82+
* ```tsx
83+
* <SelectPicker ... isDisabled />
84+
* ```
85+
*
86+
* @example Loading & disabled state
87+
* ```tsx
88+
* <SelectPicker ... isLoading isDisabled />
89+
* ```
90+
*
91+
* @example Hide selected option icon in control
92+
* ```tsx
93+
* <SelectPicker ... showSelectedOptionIcon={false} />
94+
* ```
95+
*
96+
* @example Selected option clearable
97+
* ```tsx
98+
* <SelectPicker ... isClearable />
99+
* ```
100+
*
101+
* @example Selected option clearable
102+
* ```tsx
103+
* <SelectPicker ... showSelectedOptionsCount />
104+
* ```
105+
*/
20106
const SelectPicker = ({
21107
error,
22108
icon,
@@ -33,6 +119,9 @@ const SelectPicker = ({
33119
}: SelectPickerProps) => {
34120
const { inputId, required, isDisabled } = props
35121

122+
const labelId = `${inputId}-label`
123+
const errorElementId = `${inputId}-error-msg`
124+
36125
const selectStyles = useMemo(
37126
() =>
38127
getCommonSelectStyle({
@@ -79,6 +168,7 @@ const SelectPicker = ({
79168
className="fs-13 lh-20 cn-7 fw-4 dc__block mb-0"
80169
htmlFor={inputId}
81170
data-testid={`label-${inputId}`}
171+
id={labelId}
82172
>
83173
{typeof label === 'string' ? (
84174
<span className={`flex left ${required ? 'dc__required-field' : ''}`}>
@@ -110,12 +200,15 @@ const SelectPicker = ({
110200
menuPosition="fixed"
111201
menuShouldScrollIntoView
112202
backspaceRemovesValue={false}
203+
aria-errormessage={errorElementId}
204+
aria-invalid={!!error}
205+
aria-labelledby={labelId}
113206
/>
114207
</div>
115208
</ConditionalWrap>
116209
</div>
117210
{error && (
118-
<div className="flex left dc__gap-4 cr-5 fs-11 lh-16 fw-4">
211+
<div className="flex left dc__gap-4 cr-5 fs-11 lh-16 fw-4" id={errorElementId}>
119212
<ErrorIcon className="icon-dim-16 p-1 form__icon--error dc__no-shrink dc__align-self-start" />
120213
<span className="dc__ellipsis-right__2nd-line">{error}</span>
121214
</div>

src/Shared/Components/SelectPicker/type.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,34 @@ export interface SelectPickerProps
2121
| 'isSearchable'
2222
| 'isClearable'
2323
| 'isLoading'
24-
| 'placeholder'
2524
| 'hideSelectedOptions'
2625
| 'controlShouldRenderValue'
2726
| 'closeMenuOnSelect'
2827
| 'isDisabled'
2928
| 'isLoading'
3029
| 'required'
30+
| 'isOptionDisabled'
3131
>,
32-
Required<Pick<SelectProps, 'classNamePrefix' | 'inputId' | 'name'>> {
32+
Required<Pick<SelectProps, 'classNamePrefix' | 'inputId' | 'name' | 'placeholder'>> {
33+
/**
34+
* Icon to be rendered in the control
35+
*/
3336
icon?: ReactElement
37+
/**
38+
* Error message for the select
39+
*/
3440
error?: ReactNode
41+
/**
42+
* Render function for the footer at the bottom of menu list. It is sticky by default
43+
*/
3544
renderMenuListFooter?: () => ReactNode
45+
/**
46+
* Info text for the select, if any
47+
*/
3648
helperText?: ReactNode
49+
/**
50+
* Label for the select. if required is added, the corresponding * is also added
51+
*/
3752
label?: ReactNode
3853
/**
3954
* If true, the selected option icon is shown in the container.

0 commit comments

Comments
 (0)