Skip to content

Commit

Permalink
feat(list-box): update selection style (#4753)
Browse files Browse the repository at this point in the history
Fixes #3988.
  • Loading branch information
asudoh authored Jan 15, 2020
1 parent f90251a commit 9e6335f
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 8 deletions.
2 changes: 2 additions & 0 deletions packages/components/src/components/combo-box/_combo-box.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

.#{$prefix}--combo-box .#{$prefix}--list-box__field,
.#{$prefix}--combo-box.#{$prefix}--list-box[data-invalid]
.#{$prefix}--list-box__field,
.#{$prefix}--combo-box.#{$prefix}--list-box--disabled.#{$prefix}--list-box[data-invalid]
.#{$prefix}--list-box__field {
padding: 0;
}
Expand Down
5 changes: 5 additions & 0 deletions packages/components/src/components/dropdown/_dropdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
background-color $duration--fast-01 motion(standard, productive);
opacity: 0;
visibility: inherit;
position: relative;

&:hover {
background-color: $hover-ui;
Expand Down Expand Up @@ -411,6 +412,10 @@
+ .#{$prefix}--dropdown-item .#{$prefix}--dropdown-link {
border-top-color: transparent;
}

.#{$prefix}--list-box__menu-item__selected-icon {
display: block;
}
}

// Skeleton State
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/components/dropdown/dropdown.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
{{#each items as |item index|}}
<li data-option data-value="{{value}}" class="{{@root.prefix}}--dropdown-item">
<a class="{{@root.prefix}}--dropdown-link" href="javascript:void(0)" tabindex="-1" role="menuitemradio" aria-checked="{{#if index}}false{{else}}true{{/if}}" id="{{../default.idSuffix}}-item{{@index}}">{{label}}</a>
{{ carbon-icon 'Checkmark16' class=(add @root.prefix '--list-box__menu-item__selected-icon') aria-hidden="true" }}
</li>
{{/each}}
</ul>
Expand Down
27 changes: 22 additions & 5 deletions packages/components/src/components/list-box/_list-box.scss
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ $list-box-menu-width: rem(300px);
line-height: rem(16px);
padding: rem(11px) 0;
margin: 0 $carbon--spacing-05;
padding-right: rem(32px); // 40px - `$carbon--spacing-05`
border-top: 1px solid transparent;
border-bottom: 1px solid transparent;
border-top-color: $ui-03;
Expand Down Expand Up @@ -516,7 +517,7 @@ $list-box-menu-width: rem(300px);

.#{$prefix}--list-box.#{$prefix}--list-box--inline
.#{$prefix}--list-box__menu-item__option {
margin: 0 $carbon--spacing-03;
margin: 0 rem(32px) 0 $carbon--spacing-03;

&:focus {
margin: 0;
Expand Down Expand Up @@ -546,18 +547,34 @@ $list-box-menu-width: rem(300px);

.#{$prefix}--list-box__menu-item--active {
color: $text-01;
background-color: $selected-ui;
border-bottom-color: $selected-ui;

&:hover {
background-color: $selected-ui;
}
}

.#{$prefix}--list-box__menu-item--active
.#{$prefix}--list-box__menu-item__option {
color: $text-01;
}

.#{$prefix}--list-box__menu-item__selected-icon {
display: none;
position: absolute;
top: 50%;
right: rem(16px);
transform: translateY(-50%);
fill: $icon-01;
}

.#{$prefix}--list-box--inline
.#{$prefix}--list-box__menu-item__selected-icon {
right: rem(8px);
}

.#{$prefix}--list-box__menu-item--active
.#{$prefix}--list-box__menu-item__selected-icon {
display: block;
}

.#{$prefix}--list-box__menu-item .#{$prefix}--checkbox-label {
width: 100%;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/components/list-box/list-box.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@
<ul class="{{@root.prefix}}--list-box__menu" role="combobox">
{{#each items}}
<li
class="{{@root.prefix}}--list-box__menu-item{{#if selected}} {{@root.prefix}}--list-box__menu-item--highlighted{{/if}}"
class="{{@root.prefix}}--list-box__menu-item{{#if selected}} {{@root.prefix}}--list-box__menu-item--active {{@root.prefix}}--list-box__menu-item--highlighted{{/if}}"
id="{{id}}">
<div class="{{@root.prefix}}--list-box__menu-item__option" tabindex="0">
{{label}}
{{ carbon-icon 'Checkmark16' class=(add @root.prefix '--list-box__menu-item__selected-icon') aria-hidden="true" }}
</div>
</li>
{{/each}}
Expand Down
7 changes: 6 additions & 1 deletion packages/react/src/components/ComboBox/ComboBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Downshift from 'downshift';
import PropTypes from 'prop-types';
import React from 'react';
import { settings } from 'carbon-components';
import { WarningFilled16 } from '@carbon/icons-react';
import { Checkmark16, WarningFilled16 } from '@carbon/icons-react';
import ListBox, { PropTypes as ListBoxPropTypes } from '../ListBox';
import { match, keys } from '../../internal/keyboard';
import setupGetInstanceId from '../../tools/setupGetInstanceId';
Expand Down Expand Up @@ -407,6 +407,11 @@ export default class ComboBox extends React.Component {
) : (
itemToString(item)
)}
{selectedItem === item && (
<Checkmark16
className={`${prefix}--list-box__menu-item__selected-icon`}
/>
)}
</ListBox.MenuItem>
);
}
Expand Down
7 changes: 6 additions & 1 deletion packages/react/src/components/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Downshift from 'downshift';
import PropTypes from 'prop-types';
import React from 'react';
import { settings } from 'carbon-components';
import { WarningFilled16 } from '@carbon/icons-react';
import { Checkmark16, WarningFilled16 } from '@carbon/icons-react';
import ListBox, { PropTypes as ListBoxPropTypes } from '../ListBox';
import { match, keys } from '../../internal/keyboard';

Expand Down Expand Up @@ -306,6 +306,11 @@ export default class Dropdown extends React.Component {
) : (
itemToString(item)
)}
{selectedItem === item && (
<Checkmark16
className={`${prefix}--list-box__menu-item__selected-icon`}
/>
)}
</ListBox.MenuItem>
);
})}
Expand Down

0 comments on commit 9e6335f

Please sign in to comment.