Skip to content
This repository has been archived by the owner on Oct 19, 2021. It is now read-only.

fix(DropdownV2): match experimental spec #2093

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9c15d30
docs(DropdownV2): add invalid knob
emyarod Mar 20, 2019
b56af4f
chore: bump carbon-components version
emyarod Mar 22, 2019
64f8279
fix(ListBox): add v10 listbox classes
emyarod Mar 25, 2019
464a6d2
fix(DropdownV2): add disabled form and v10 classes
emyarod Mar 25, 2019
3ad4209
refactor(ListBox): deprecate `type` prop
emyarod Mar 25, 2019
84ff1c8
feat(DropdownV2): integrate v10 listbox
emyarod Mar 25, 2019
c533d1d
test: update snapshots and inline variant test
emyarod Mar 25, 2019
65b2978
Revert "refactor(ListBox): deprecate `type` prop"
emyarod Mar 25, 2019
e507ddc
Revert "test: update snapshots and inline variant test"
emyarod Mar 25, 2019
3913929
docs(ListBox): add propType
emyarod Mar 25, 2019
e2b91c6
fix(Dropdown): use listbox light and invalid style
emyarod Mar 25, 2019
0c83e5b
docs(DropdownV2): change options list placeholder
emyarod Mar 25, 2019
ae1c6b0
fix(Dropdown): remove breaking changes flag
emyarod Mar 25, 2019
bd39568
test: update snapshots
emyarod Mar 25, 2019
65bb27d
chore: bump carbon-components version
emyarod Mar 26, 2019
aa39bdd
chore: bump carbon-components version
emyarod Mar 26, 2019
dab328e
chore: bump carbon-components version
emyarod Mar 27, 2019
0b13ae3
chore: bump carbon-components version
emyarod Mar 28, 2019
3af80fa
fix(ListBoxMenuItem): add conditional for v10
emyarod Mar 28, 2019
826f143
fix(DropdownV2): add disabled class
emyarod Mar 28, 2019
d233cef
fix(DropdownV2): add light class
emyarod Mar 28, 2019
cb24d1d
chore: update snapshots
emyarod Mar 28, 2019
50b733c
refactor(ListBoxMenuItem): remove unneeded attrs
emyarod Mar 28, 2019
0401efa
chore: bump carbon-components version
emyarod Mar 28, 2019
174f1e1
refactor(DropdownV2): remove wrapper from v9
emyarod Mar 28, 2019
f5e719d
chore: update snapshot
emyarod Mar 28, 2019
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
Binary file removed .yarn-offline-mirror/carbon-components-9.87.2.tgz
Binary file not shown.
Binary file added .yarn-offline-mirror/carbon-components-9.90.9.tgz
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
"babel-plugin-dev-expression": "^0.2.1",
"babel-plugin-react-docgen": "^2.0.0",
"bowser": "^1.6.1",
"carbon-components": "^9.87.2",
"carbon-components": "^9.90.9",
"carbon-icons": "^7.0.5",
"chalk": "^2.3.0",
"cli-table": "^0.3.0",
Expand Down
7 changes: 6 additions & 1 deletion src/components/DropdownV2/DropdownV2-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,17 @@ const types = {

const props = () => ({
type: select('Dropdown type (type)', types, 'default'),
label: text('Label (label)', 'Label'),
label: text('Label (label)', 'Dropdown menu options'),
ariaLabel: text('Aria Label (ariaLabel)', 'Dropdown'),
disabled: boolean('Disabled (disabled)', false),
light: boolean('Light variant (light)', false),
titleText: text('Title (titleText)', 'This is not a dropdown title.'),
helperText: text('Helper text (helperText)', 'This is not some helper text.'),
invalid: boolean('Show form validation UI (invalid)', false),
invalidText: text(
'Form validation UI content (invalidText)',
'A valid value is required'
),
});

const itemToElement = item => {
Expand Down
171 changes: 110 additions & 61 deletions src/components/DropdownV2/DropdownV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import Downshift from 'downshift';
import PropTypes from 'prop-types';
import React from 'react';
import { settings } from 'carbon-components';
import WarningFilled16 from '@carbon/icons-react/lib/warning--filled/16';
import ListBox, { PropTypes as ListBoxPropTypes } from '../ListBox';
import { componentsX } from '../../internal/FeatureFlags';

const { prefix } = settings;

Expand Down Expand Up @@ -44,6 +46,21 @@ export default class DropdownV2 extends React.Component {
PropTypes.string,
]),

/**
* Specify whether you want the inline version of this control
*/
inline: PropTypes.bool,

/**
* Specify if the currently selected value is invalid.
*/
invalid: PropTypes.bool,

/**
* Message which is displayed if the value is invalid.
*/
invalidText: PropTypes.string,

/**
* Helper function passed to downshift that allows the library to render a
* given item to a string label. By default, it extracts the `label` field
Expand Down Expand Up @@ -130,85 +147,117 @@ export default class DropdownV2 extends React.Component {
type,
initialSelectedItem,
selectedItem,
light,
id,
titleText,
helperText,
light,
invalid,
invalidText,
} = this.props;
const className = cx(`${prefix}--dropdown`, containerClassName, {
[`${prefix}--dropdown--light`]: light,
const inline = type === 'inline';
const className = ({ isOpen }) =>
cx(`${prefix}--dropdown`, containerClassName, {
[`${prefix}--dropdown--invalid`]: invalid,
[`${prefix}--dropdown--open`]: isOpen,
[`${prefix}--dropdown--inline`]: inline,
[`${prefix}--dropdown--disabled`]: disabled,
[`${prefix}--dropdown--light`]: light,
});
const titleClasses = cx(`${prefix}--label`, {
[`${prefix}--label--disabled`]: disabled,
});
const title = titleText ? (
<label htmlFor={id} className={`${prefix}--label`}>
<label htmlFor={id} className={titleClasses}>
{titleText}
</label>
) : null;
const helperClasses = cx(`${prefix}--form__helper-text`, {
[`${prefix}--form__helper-text--disabled`]: disabled,
});
const helper = helperText ? (
<div className={`${prefix}--form__helper-text`}>{helperText}</div>
<div className={helperClasses}>{helperText}</div>
) : null;
const wrapperClasses = cx(
`${prefix}--dropdown__wrapper`,
`${prefix}--list-box__wrapper`,
{
[`${prefix}--dropdown__wrapper--inline`]: inline,
[`${prefix}--list-box__wrapper--inline`]: inline,
[`${prefix}--dropdown__wrapper--inline--invalid`]: inline && invalid,
[`${prefix}--list-box__wrapper--inline--invalid`]: inline && invalid,
}
);

// needs to be Capitalized for react to render it correctly
const ItemToElement = itemToElement;
const Dropdown = (
<Downshift
id={id}
onChange={this.handleOnChange}
itemToString={itemToString}
defaultSelectedItem={initialSelectedItem}
selectedItem={selectedItem}>
{({
isOpen,
itemToString,
selectedItem,
highlightedIndex,
getRootProps,
getButtonProps,
getItemProps,
getLabelProps,
}) => (
<ListBox
type={type}
className={className}
disabled={disabled}
ariaLabel={ariaLabel}
{...getRootProps({ refKey: 'innerRef' })}>
<ListBox.Field {...getButtonProps({ disabled })}>
<span
className={`${prefix}--list-box__label`}
{...getLabelProps()}>
{selectedItem ? itemToString(selectedItem) : label}
</span>
<ListBox.MenuIcon isOpen={isOpen} />
</ListBox.Field>
{isOpen && (
<ListBox.Menu>
{items.map((item, index) => (
<ListBox.MenuItem
key={itemToString(item)}
isActive={selectedItem === item}
isHighlighted={
highlightedIndex === index || selectedItem === item
}
{...getItemProps({ item, index })}>
{itemToElement ? (
<ItemToElement key={itemToString(item)} {...item} />
) : (
itemToString(item)
)}
</ListBox.MenuItem>
))}
</ListBox.Menu>
)}
</ListBox>
)}
</Downshift>
);
return title || helper ? (
<>
{title}
{helper}
{Dropdown}
{!inline && helper}
<Downshift
id={id}
onChange={this.handleOnChange}
itemToString={itemToString}
defaultSelectedItem={initialSelectedItem}
selectedItem={selectedItem}>
{({
isOpen,
itemToString,
selectedItem,
highlightedIndex,
getRootProps,
getButtonProps,
getItemProps,
getLabelProps,
}) => (
<ListBox
type={type}
className={className({ isOpen })}
disabled={disabled}
ariaLabel={ariaLabel}
isOpen={isOpen}
invalid={invalid}
invalidText={invalidText}
{...getRootProps({ refKey: 'innerRef' })}>
{componentsX && invalid && (
<WarningFilled16
className={`${prefix}--list-box__invalid-icon`}
/>
)}
<ListBox.Field {...getButtonProps({ disabled })}>
<span
className={`${prefix}--list-box__label`}
{...getLabelProps()}>
{selectedItem ? itemToString(selectedItem) : label}
</span>
<ListBox.MenuIcon isOpen={isOpen} />
</ListBox.Field>
{isOpen && (
<ListBox.Menu>
{items.map((item, index) => (
<ListBox.MenuItem
key={itemToString(item)}
isActive={selectedItem === item}
isHighlighted={
highlightedIndex === index || selectedItem === item
}
{...getItemProps({ item, index })}>
{itemToElement ? (
<ItemToElement key={itemToString(item)} {...item} />
) : (
itemToString(item)
)}
</ListBox.MenuItem>
))}
</ListBox.Menu>
)}
</ListBox>
)}
</Downshift>
</>
);
return componentsX ? (
<div className={wrapperClasses}>{Dropdown}</div>
) : (
Dropdown
);
Expand Down
16 changes: 10 additions & 6 deletions src/components/DropdownV2/__snapshots__/DropdownV2-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ exports[`DropdownV2 should render 1`] = `
className="bx--dropdown"
disabled={false}
innerRef={[Function]}
isOpen={false}
type="default"
>
<div
Expand Down Expand Up @@ -235,14 +236,15 @@ exports[`DropdownV2 should render DropdownItem components 1`] = `
>
<ListBox
ariaLabel="Choose an item"
className="bx--dropdown"
className="bx--dropdown bx--dropdown--open"
disabled={false}
innerRef={[Function]}
isOpen={true}
type="default"
>
<div
aria-label="Choose an item"
className="bx--dropdown bx--list-box"
className="bx--dropdown bx--dropdown--open bx--list-box bx--list-box--expanded"
onClick={[Function]}
onKeyDown={[Function]}
role="listbox"
Expand Down Expand Up @@ -649,14 +651,15 @@ exports[`DropdownV2 should render custom item components 1`] = `
>
<ListBox
ariaLabel="Choose an item"
className="bx--dropdown"
className="bx--dropdown bx--dropdown--open"
disabled={false}
innerRef={[Function]}
isOpen={true}
type="default"
>
<div
aria-label="Choose an item"
className="bx--dropdown bx--list-box"
className="bx--dropdown bx--dropdown--open bx--list-box bx--list-box--expanded"
onClick={[Function]}
onKeyDown={[Function]}
role="listbox"
Expand Down Expand Up @@ -955,14 +958,15 @@ exports[`DropdownV2 should render with strings as items 1`] = `
>
<ListBox
ariaLabel="Choose an item"
className="bx--dropdown"
className="bx--dropdown bx--dropdown--open"
disabled={false}
innerRef={[Function]}
isOpen={true}
type="default"
>
<div
aria-label="Choose an item"
className="bx--dropdown bx--list-box"
className="bx--dropdown bx--dropdown--open bx--list-box bx--list-box--expanded"
onClick={[Function]}
onKeyDown={[Function]}
role="listbox"
Expand Down
5 changes: 4 additions & 1 deletion src/components/ListBox/ListBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ListBoxField from './ListBoxField';
import ListBoxMenu from './ListBoxMenu';
import { ListBoxType } from './ListBoxPropTypes';
import childrenOf from '../../prop-types/childrenOf';
import WarningFilled16 from '@carbon/icons-react/lib/warning--filled/16';

const { prefix } = settings;

Expand Down Expand Up @@ -42,6 +43,7 @@ const ListBox = ({
invalidText,
light,
innerTabIndex,
isOpen,
...rest
}) => {
const className = cx({
Expand All @@ -50,6 +52,7 @@ const ListBox = ({
[`${prefix}--list-box--inline`]: type === 'inline',
[`${prefix}--list-box--disabled`]: disabled,
[`${prefix}--list-box--light`]: light,
[`${prefix}--list-box--expanded`]: isOpen,
});
return (
<>
Expand All @@ -74,7 +77,7 @@ const ListBox = ({
};

ListBox.propTypes = {
children: childrenOf([ListBoxField, ListBoxMenu]),
children: childrenOf([ListBoxField, ListBoxMenu, WarningFilled16]),

/**
* Specify a class name to be applied on the containing list box node
Expand Down
9 changes: 8 additions & 1 deletion src/components/ListBox/ListBoxMenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import cx from 'classnames';
import React from 'react';
import PropTypes from 'prop-types';
import { settings } from 'carbon-components';
import { componentsX } from '../../internal/FeatureFlags';

const { prefix } = settings;

Expand All @@ -25,7 +26,13 @@ const ListBoxMenuItem = ({ children, isActive, isHighlighted, ...rest }) => {
});
return (
<div className={className} {...rest}>
{children}
{componentsX ? (
<div className={`${prefix}--list-box__menu-item__option`}>
{children}
</div>
) : (
children
)}
</div>
);
};
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3195,10 +3195,10 @@ capture-stack-trace@^1.0.0:
resolved "https://registry.yarnpkg.com/capture-stack-trace/-/capture-stack-trace-1.0.1.tgz#a6c0bbe1f38f3aa0b92238ecb6ff42c344d4135d"
integrity sha512-mYQLZnx5Qt1JgB1WEiMCf2647plpGeQ2NMR/5L0HNZzGQo4fuSPnK+wjfPnKZV0aiJDgzmWqqkV/g7JD+DW0qw==

carbon-components@^9.87.2:
version "9.87.2"
resolved "https://registry.yarnpkg.com/carbon-components/-/carbon-components-9.87.2.tgz#20a96389975529526fd990789461cf20595a6273"
integrity sha512-wUbpYabgaX/rzBVWlKhBzQgO7W/62eFYJ6fnH9ATcz78vqRZy4ptzk1Z5EnyE4CjMOUnCUQrt/VuVSHP88LNtg==
carbon-components@^9.90.9:
version "9.90.9"
resolved "https://registry.yarnpkg.com/carbon-components/-/carbon-components-9.90.9.tgz#3ae43bb29d1ede088c1c683ddc9643bb4feb160e"
integrity sha512-h7ugDyO0XjHoe6faO1w27OckmLAm2D/As6H9LVTlW8HEFsRiQjhor4v6k3Ihz6cAAeMK7+DM7eYTaKNR/6dOmA==
dependencies:
carbon-icons "^7.0.7"
flatpickr "4.5.7"
Expand Down