@@ -17,6 +17,92 @@ import {
17
17
} from './common'
18
18
import { SelectPickerOptionType , SelectPickerProps } from './type'
19
19
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
+ */
20
106
const SelectPicker = ( {
21
107
error,
22
108
icon,
@@ -33,6 +119,9 @@ const SelectPicker = ({
33
119
} : SelectPickerProps ) => {
34
120
const { inputId, required, isDisabled } = props
35
121
122
+ const labelId = `${ inputId } -label`
123
+ const errorElementId = `${ inputId } -error-msg`
124
+
36
125
const selectStyles = useMemo (
37
126
( ) =>
38
127
getCommonSelectStyle ( {
@@ -79,6 +168,7 @@ const SelectPicker = ({
79
168
className = "fs-13 lh-20 cn-7 fw-4 dc__block mb-0"
80
169
htmlFor = { inputId }
81
170
data-testid = { `label-${ inputId } ` }
171
+ id = { labelId }
82
172
>
83
173
{ typeof label === 'string' ? (
84
174
< span className = { `flex left ${ required ? 'dc__required-field' : '' } ` } >
@@ -110,12 +200,15 @@ const SelectPicker = ({
110
200
menuPosition = "fixed"
111
201
menuShouldScrollIntoView
112
202
backspaceRemovesValue = { false }
203
+ aria-errormessage = { errorElementId }
204
+ aria-invalid = { ! ! error }
205
+ aria-labelledby = { labelId }
113
206
/>
114
207
</ div >
115
208
</ ConditionalWrap >
116
209
</ div >
117
210
{ 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 } >
119
212
< ErrorIcon className = "icon-dim-16 p-1 form__icon--error dc__no-shrink dc__align-self-start" />
120
213
< span className = "dc__ellipsis-right__2nd-line" > { error } </ span >
121
214
</ div >
0 commit comments