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

fix(dropdown): revert id change to have stable identifier #4935

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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