Skip to content

Commit 452e065

Browse files
committed
Add disabled property to Select and ButtonSelect items
1 parent d743e95 commit 452e065

File tree

5 files changed

+83
-11
lines changed

5 files changed

+83
-11
lines changed

packages/react-components/source/react/internal/action-menu-list/ActionMenuList.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,12 @@ class ActionMenuList extends Component {
257257
icon={icon}
258258
svg={svg}
259259
onMouseEnter={() => onMouseEnterItem(index)}
260-
onClick={e => !disabled && executeAction(e, onClick, actionId)}
261260
disabled={disabled}
261+
onClick={
262+
disabled
263+
? undefined
264+
: e => executeAction(e, onClick, actionId)
265+
}
262266
ref={el => {
263267
this.actionRefs[index] = el;
264268
}}

packages/react-components/source/react/internal/option-menu-list/OptionMenuList.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const propTypes = {
2626
value: PropTypes.string.isRequired,
2727
label: PropTypes.node.isRequired,
2828
icon: PropTypes.oneOf(Icon.AVAILABLE_ICONS),
29+
disabled: PropTypes.bool,
2930
}),
3031
),
3132
selected: PropTypes.oneOfType([
@@ -344,15 +345,16 @@ class OptionMenuList extends Component {
344345
}}
345346
{...rest}
346347
>
347-
{options.map(({ value, label, icon, svg }, index) => (
348+
{options.map(({ value, label, icon, svg, disabled }, index) => (
348349
<OptionMenuListItem
349350
id={getOptionId(id, value)}
350351
key={value}
351352
focused={index === focusedIndex}
352353
selected={selectionSet.has(value)}
353354
icon={icon}
354355
svg={svg}
355-
onClick={() => onClickItem(value)}
356+
disabled={disabled}
357+
onClick={disabled ? undefined : () => onClickItem(value)}
356358
onMouseEnter={() => onMouseEnterItem(index)}
357359
ref={option => {
358360
this.optionRefs[index] = option;

packages/react-components/source/react/internal/option-menu-list/OptionMenuListItem.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,29 @@ const propTypes = {
1515
svg: PropTypes.element,
1616
onClick: PropTypes.func.isRequired,
1717
onMouseEnter: PropTypes.func.isRequired,
18+
disabled: PropTypes.bool,
1819
};
1920

2021
const defaultProps = {
2122
icon: null,
2223
svg: null,
24+
disabled: false,
2325
};
2426

2527
/* eslint-disable jsx-a11y/click-events-have-key-events */
2628
const OptionMenuListItem = forwardRef(
2729
(
28-
{ id, children, focused, selected, icon, svg, onClick, onMouseEnter },
30+
{
31+
id,
32+
children,
33+
focused,
34+
selected,
35+
icon,
36+
svg,
37+
onClick,
38+
onMouseEnter,
39+
disabled,
40+
},
2941
ref,
3042
) => (
3143
<li
@@ -34,6 +46,7 @@ const OptionMenuListItem = forwardRef(
3446
className={classNames('rc-menu-list-item', {
3547
'rc-menu-list-item-focused': focused,
3648
'rc-menu-list-item-selected': selected,
49+
'rc-menu-list-item-disabled': disabled,
3750
})}
3851
aria-selected={selected}
3952
onClick={onClick}

packages/react-components/source/react/library/button-select/ButtonSelect.md

+22
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,28 @@ const options = [
2424
/>;
2525
```
2626

27+
### Disable rows
28+
29+
Use the `disabled` object property to disable a row in a dropdown and prevent onClick actions from happening.
30+
31+
```jsx
32+
const options = [
33+
{ value: 'hello', label: 'Hello' },
34+
{ value: 'world', label: 'World' },
35+
{ value: 'hi', label: 'Hi', disabled: true },
36+
{ value: 'mom', label: 'Mom', disabled: true },
37+
];
38+
39+
<ButtonSelect
40+
options={options}
41+
value={state.value}
42+
onChange={value => {
43+
console.log('New Value:', value);
44+
setState({ value });
45+
}}
46+
/>;
47+
```
48+
2749
## Types
2850

2951
The visual types of `ButtonSelect` are "primary", "secondary", "tertiary", "danger", "transparent", "text".

packages/react-components/source/react/library/select/Select.md

+38-7
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const style = { margin: 10 };
2828

2929
<div>
3030
<Select
31-
id="button-select-one"
3231
name="select-example"
3332
options={options}
3433
placeholder="Select your language"
@@ -42,6 +41,41 @@ const style = { margin: 10 };
4241
</div>;
4342
```
4443

44+
### Disable rows
45+
46+
Use the `disabled` object property to disable a row in a dropdown and prevent onClick actions from happening.
47+
48+
```jsx
49+
const options = [
50+
{ value: 'en', label: 'English' },
51+
{ value: 'ru', label: 'русский' },
52+
{ value: 'zh', label: '中文' },
53+
{ value: 'sq', label: 'Albanian' },
54+
{ value: 'ar', label: 'Arabic' },
55+
{ value: 'eu', label: 'Basque', disabled: true },
56+
{ value: 'bn', label: 'Bengali', disabled: true },
57+
{ value: 'bs', label: 'Bosnian', disabled: true },
58+
{ value: 'bg', label: 'Bulgarian', disabled: true },
59+
{ value: 'ca', label: 'Catalan', disabled: true },
60+
];
61+
62+
const style = { margin: 10 };
63+
64+
<div>
65+
<Select
66+
name="disabled-select-example"
67+
options={options}
68+
placeholder="Select your language"
69+
style={style}
70+
value={state.value1}
71+
onChange={value1 => {
72+
console.log('New Value:', value1);
73+
setState({ value1 });
74+
}}
75+
/>
76+
</div>;
77+
```
78+
4579
## Variations
4680

4781
### Autocomplete
@@ -65,8 +99,7 @@ const style = { margin: 10 };
6599

66100
<div>
67101
<Select
68-
id="button-select-one"
69-
name="select-example-one"
102+
name="autocomplete-example"
70103
options={options}
71104
placeholder="Select your fruit"
72105
style={style}
@@ -109,8 +142,7 @@ const style = { margin: 10 };
109142

110143
<div>
111144
<Select
112-
id="button-select-one"
113-
name="select-example-one"
145+
name="multi-select-example"
114146
options={options}
115147
placeholder="Select your language"
116148
style={style}
@@ -152,8 +184,7 @@ const style = { margin: 10 };
152184

153185
<div>
154186
<Select
155-
id="button-select-one"
156-
name="select-example-one"
187+
name="multi-select-immediate-example"
157188
options={options}
158189
placeholder="Select your language"
159190
style={style}

0 commit comments

Comments
 (0)