Skip to content

Commit 84de2dc

Browse files
feat(multiselect): allow disabled listbox items (#9859)
* feat(multiselect): allow disabled listbox items * fix(listbox): use disabled-02 instead of disabled-03 for items Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 3f7fbdf commit 84de2dc

File tree

5 files changed

+61
-2
lines changed

5 files changed

+61
-2
lines changed

packages/carbon-react/src/components/MultiSelect/MultiSelect.stories.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ const items = [
2020
},
2121
{
2222
id: 'downshift-1-item-2',
23-
text: 'Option 3',
23+
text: 'Option 3 - a disabled item',
24+
disabled: true,
2425
},
2526
{
2627
id: 'downshift-1-item-3',

packages/components/src/components/list-box/_list-box.scss

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,34 @@ $list-box-menu-width: rem(300px);
658658
color: $disabled-02;
659659
}
660660

661+
.#{$prefix}--list-box__menu-item[disabled],
662+
.#{$prefix}--list-box__menu-item[disabled] *,
663+
.#{$prefix}--list-box__menu-item[disabled]:hover {
664+
color: $disabled-02;
665+
cursor: not-allowed;
666+
outline: none;
667+
}
668+
669+
.#{$prefix}--list-box__menu-item[disabled]:hover {
670+
background-color: revert;
671+
}
672+
673+
.#{$prefix}--list-box__menu-item[disabled]
674+
.#{$prefix}--checkbox-label::before {
675+
border-color: $disabled-02;
676+
}
677+
678+
.#{$prefix}--list-box__menu-item[disabled]
679+
.#{$prefix}--list-box__menu-item__option {
680+
border-top-color: $ui-03;
681+
}
682+
683+
.#{$prefix}--list-box__menu-item[disabled]:hover
684+
+ .#{$prefix}--list-box__menu-item
685+
.#{$prefix}--list-box__menu-item__option {
686+
border-top-color: $ui-03;
687+
}
688+
661689
.#{$prefix}--list-box.#{$prefix}--list-box--inline
662690
.#{$prefix}--list-box__menu-item__option {
663691
margin: 0 $carbon--spacing-03;

packages/react/src/components/MultiSelect/MultiSelect-story.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ const items = [
3232
},
3333
{
3434
id: 'downshift-1-item-2',
35-
text: 'Option 3',
35+
text: 'Option 3 - a disabled item',
36+
disabled: true,
3637
},
3738
{
3839
id: 'downshift-1-item-3',

packages/react/src/components/MultiSelect/MultiSelect.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ const MultiSelect = React.forwardRef(function MultiSelect(
282282
// we don't want Downshift to set aria-selected for us
283283
// we also don't want to set 'false' for reader verbosity's sake
284284
['aria-selected']: isChecked ? true : null,
285+
disabled: item?.disabled,
285286
});
286287
const itemText = itemToString(item);
287288
const isChecked =

packages/styles/scss/components/list-box/_list-box.scss

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,34 @@ $list-box-menu-width: rem(300px);
668668
color: $text-disabled;
669669
}
670670

671+
.#{$prefix}--list-box__menu-item[disabled],
672+
.#{$prefix}--list-box__menu-item[disabled] *,
673+
.#{$prefix}--list-box__menu-item[disabled]:hover {
674+
color: $text-disabled;
675+
cursor: not-allowed;
676+
outline: none;
677+
}
678+
679+
.#{$prefix}--list-box__menu-item[disabled]:hover {
680+
background-color: revert;
681+
}
682+
683+
.#{$prefix}--list-box__menu-item[disabled]
684+
.#{$prefix}--checkbox-label::before {
685+
border-color: $text-disabled;
686+
}
687+
688+
.#{$prefix}--list-box__menu-item[disabled]
689+
.#{$prefix}--list-box__menu-item__option {
690+
border-top-color: $border-subtle;
691+
}
692+
693+
.#{$prefix}--list-box__menu-item[disabled]:hover
694+
+ .#{$prefix}--list-box__menu-item
695+
.#{$prefix}--list-box__menu-item__option {
696+
border-top-color: $border-subtle;
697+
}
698+
671699
.#{$prefix}--list-box.#{$prefix}--list-box--inline
672700
.#{$prefix}--list-box__menu-item__option {
673701
margin: 0 $spacing-03;

0 commit comments

Comments
 (0)