Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(list-box): update selection style #4753

Merged
merged 8 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -178,6 +178,7 @@
background-color $duration--fast-01 motion(standard, productive);
opacity: 0;
visibility: inherit;
position: relative;

&:hover {
background-color: $hover-ui;
Expand Down Expand Up @@ -396,6 +397,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
13 changes: 13 additions & 0 deletions packages/components/src/components/list-box/_list-box.scss
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,19 @@ $list-box-menu-width: rem(300px);
color: $text-01;
}

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

.#{$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 @@ -388,6 +388,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';
import setupGetInstanceId from '../../tools/setupGetInstanceId';
Expand Down Expand Up @@ -293,6 +293,11 @@ export default class Dropdown extends React.Component {
) : (
itemToString(item)
)}
{selectedItem === item && (
<Checkmark16
className={`${prefix}--list-box__menu-item__selected-icon`}
/>
)}
</ListBox.MenuItem>
))}
</ListBox.Menu>
Expand Down