Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

fix(MenuSelect): Adds id prop to MenuSelect #3073

Merged
merged 1 commit into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const cx = createClassNames('MenuSelect');

class MenuSelect extends Component {
static propTypes = {
id: PropTypes.string,
items: PropTypes.arrayOf(
PropTypes.shape({
label: PropTypes.string.isRequired,
Expand Down Expand Up @@ -44,13 +45,14 @@ class MenuSelect extends Component {
};

render() {
const { items, canRefine, translate, className } = this.props;
const { id, items, canRefine, translate, className } = this.props;

return (
<div
className={classNames(cx('', !canRefine && '-noRefinement'), className)}
>
<select
id={id}
value={this.selectedValue}
onChange={this.handleSelectChange}
className={cx('select')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ describe('MenuSelect', () => {
expect(tree).toMatchSnapshot();
});

it('default menu select with custom id', () => {
const id = 'menu-select';
const wrapper = mount(
<MenuSelect id={id} refine={() => {}} items={[]} canRefine={false} />
);

const select = wrapper.find('select').getDOMNode();
expect(select.getAttribute('id')).toEqual(id);
});

it('default menu select with no refinement', () => {
const tree = renderer
.create(<MenuSelect refine={() => {}} items={[]} canRefine={false} />)
Expand Down
1 change: 1 addition & 0 deletions packages/react-instantsearch-dom/src/widgets/MenuSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import MenuSelect from '../components/MenuSelect';
* @kind widget
* @requirements The attribute passed to the `attribute` prop must be present in "attributes for faceting"
* on the Algolia dashboard or configured as `attributesForFaceting` via a set settings call to the Algolia API.
* @propType {string} id - the id of the select input
* @propType {string} attribute - the name of the attribute in the record
* @propType {string} [defaultRefinement] - the value of the item selected by default
* @propType {number} [limit=10] - the minimum number of diplayed items
Expand Down