Skip to content

Commit

Permalink
fix(dropdown): revert id change to have stable identifier (#4935)
Browse files Browse the repository at this point in the history
Co-authored-by: Akira Sudoh <[email protected]>
  • Loading branch information
joshblack and asudoh committed Jan 6, 2020
1 parent 90feb07 commit a506f76
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
15 changes: 3 additions & 12 deletions packages/react/src/components/Dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { settings } from 'carbon-components';
import { WarningFilled16 } from '@carbon/icons-react';
import ListBox, { PropTypes as ListBoxPropTypes } from '../ListBox';
import { match, keys } from '../../internal/keyboard';
import setupGetInstanceId from '../../tools/setupGetInstanceId';

const { prefix } = settings;

Expand All @@ -25,8 +24,6 @@ const defaultItemToString = item => {
return item ? item.label : '';
};

const getInstanceId = setupGetInstanceId();

export default class Dropdown extends React.Component {
static propTypes = {
/**
Expand Down Expand Up @@ -152,10 +149,6 @@ export default class Dropdown extends React.Component {
helperText: '',
};

constructor(props) {
super(props);
this.dropdownInstanceId = getInstanceId();
}
handleOnChange = selectedItem => {
if (this.props.onChange) {
this.props.onChange({ selectedItem });
Expand Down Expand Up @@ -197,10 +190,8 @@ export default class Dropdown extends React.Component {
[`${prefix}--label--disabled`]: disabled,
});

const dropdownId = `dropdown-${this.dropdownInstanceId}`;

const title = titleText ? (
<label htmlFor={dropdownId} className={titleClasses}>
<label htmlFor={id} className={titleClasses}>
{titleText}
</label>
) : null;
Expand Down Expand Up @@ -247,7 +238,7 @@ export default class Dropdown extends React.Component {
<ListBox
type={type}
size={size}
id={dropdownId}
id={id}
aria-label={ariaLabel}
className={className({ isOpen })}
disabled={disabled}
Expand Down Expand Up @@ -286,7 +277,7 @@ export default class Dropdown extends React.Component {
/>
</ListBox.Field>
{isOpen && (
<ListBox.Menu aria-labelledby={dropdownId} id={id}>
<ListBox.Menu aria-labelledby={id} id={id}>
{items.map((item, index) => (
<ListBox.MenuItem
key={itemToString(item)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ exports[`Dropdown should render 1`] = `
<ListBox
className="bx--dropdown"
disabled={false}
id="dropdown-1"
id="test-dropdown"
innerRef={[Function]}
isOpen={false}
light={false}
type="default"
>
<div
className="bx--dropdown bx--list-box"
id="dropdown-1"
id="test-dropdown"
onClick={[Function]}
onKeyDown={[Function]}
role="listbox"
Expand Down Expand Up @@ -242,15 +242,15 @@ exports[`Dropdown should render custom item components 1`] = `
<ListBox
className="bx--dropdown bx--dropdown--open"
disabled={false}
id="dropdown-5"
id="test-dropdown"
innerRef={[Function]}
isOpen={true}
light={false}
type="default"
>
<div
className="bx--dropdown bx--dropdown--open bx--list-box bx--list-box--expanded"
id="dropdown-5"
id="test-dropdown"
onClick={[Function]}
onKeyDown={[Function]}
role="listbox"
Expand Down Expand Up @@ -344,11 +344,11 @@ exports[`Dropdown should render custom item components 1`] = `
</div>
</ListBoxField>
<ListBoxMenu
aria-labelledby="dropdown-5"
aria-labelledby="test-dropdown"
id="test-dropdown"
>
<div
aria-labelledby="dropdown-5"
aria-labelledby="test-dropdown"
className="bx--list-box__menu"
id="test-dropdown__menu"
role="listbox"
Expand Down Expand Up @@ -576,15 +576,15 @@ exports[`Dropdown should render with strings as items 1`] = `
<ListBox
className="bx--dropdown bx--dropdown--open"
disabled={false}
id="dropdown-4"
id="test-dropdown"
innerRef={[Function]}
isOpen={true}
light={false}
type="default"
>
<div
className="bx--dropdown bx--dropdown--open bx--list-box bx--list-box--expanded"
id="dropdown-4"
id="test-dropdown"
onClick={[Function]}
onKeyDown={[Function]}
role="listbox"
Expand Down Expand Up @@ -678,11 +678,11 @@ exports[`Dropdown should render with strings as items 1`] = `
</div>
</ListBoxField>
<ListBoxMenu
aria-labelledby="dropdown-4"
aria-labelledby="test-dropdown"
id="test-dropdown"
>
<div
aria-labelledby="dropdown-4"
aria-labelledby="test-dropdown"
className="bx--list-box__menu"
id="test-dropdown__menu"
role="listbox"
Expand Down

0 comments on commit a506f76

Please sign in to comment.