Skip to content

Commit 7d64334

Browse files
authored
fix: prevent disabled and readonly select from opening (#1124)
* fix: disabled and readonly select disable opening * fix: adjust logic * fix: add back onclick
1 parent 3a22ad8 commit 7d64334

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/Select/Select.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ const Select = React.forwardRef(({
105105
{...props}
106106
className={selectClasses}
107107
id={id}
108-
onClick={handleClick}
109108
ref={divRef}>
110109
<div className={selectControlClasses}>
111110
<span aria-label={selectAriaLabel} className='fd-select__text-content'>{textContent}</span>
@@ -114,12 +113,16 @@ const Select = React.forwardRef(({
114113
</div>
115114
);
116115

116+
const tabIndex = disabled ? -1 : 0;
117+
117118
const wrappedSelectControl = (
118119
<FormValidationOverlay
119120
aria-disabled={disabled}
120121
aria-readonly={readOnly}
121122
control={selectControl}
123+
onClick={handleClick}
122124
role={'combobox'}
125+
tabIndex={tabIndex}
123126
validationState={validationState} />
124127
);
125128

@@ -162,6 +165,8 @@ const Select = React.forwardRef(({
162165
</List>
163166
</>)}
164167
control={wrappedSelectControl}
168+
disableKeyPressHandler={disabled || readOnly}
169+
disableTriggerOnClick={disabled || readOnly}
165170
firstFocusIndex={firstFocusIndex}
166171
noArrow
167172
placement='bottom-start'

src/Select/__stories__/__snapshots__/Select.stories.storyshot

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,11 @@ exports[`Storyshots Component API/Select Disabled 1`] = `
152152
className="fd-popover__control"
153153
>
154154
<div
155-
aria-controls="fd-mocked-short-id"
156155
aria-disabled={true}
157-
aria-expanded={false}
158-
aria-haspopup="listbox"
159156
className="fd-select"
160157
onClick={[Function]}
161-
onKeyPress={[Function]}
162158
role="combobox"
163-
tabIndex={0}
159+
tabIndex={-1}
164160
>
165161
<div
166162
className="fd-select__control is-disabled"
@@ -334,13 +330,9 @@ exports[`Storyshots Component API/Select Read Only 1`] = `
334330
className="fd-popover__control"
335331
>
336332
<div
337-
aria-controls="fd-mocked-short-id"
338-
aria-expanded={false}
339-
aria-haspopup="listbox"
340333
aria-readonly={true}
341334
className="fd-select"
342335
onClick={[Function]}
343-
onKeyPress={[Function]}
344336
role="combobox"
345337
tabIndex={0}
346338
>

0 commit comments

Comments
 (0)