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

Commit 9c745b9

Browse files
bellsworth13asudoh
authored andcommitted
fix(DataTable): removed hardcoded id, resolves #735 (#760)
* fix(DataTable): removed hardcoded id * chore(TableToolBarSearch): added correct definition for prop * fix(TableToolbarSearch): added default prop for id * chore(TableToolbarSearch): default prop
1 parent 74cf401 commit 9c745b9

File tree

5 files changed

+26
-10
lines changed

5 files changed

+26
-10
lines changed

src/components/DataTable/TableToolbarSearch.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ import cx from 'classnames';
22
import PropTypes from 'prop-types';
33
import React from 'react';
44
import Search from '../Search';
5+
import setupGetInstanceId from './tools/instanceId';
6+
7+
const getInstanceId = setupGetInstanceId();
58

69
const TableToolbarSearch = ({
710
className,
811
searchContainerClass,
912
onChange,
13+
id = `data-table-search-${getInstanceId()}`,
1014
...rest
1115
}) => {
1216
const searchContainerClasses = cx(
@@ -19,7 +23,7 @@ const TableToolbarSearch = ({
1923
className={className}
2024
{...rest}
2125
small
22-
id="search-2"
26+
id={id}
2327
labelText="Filter table"
2428
placeHolderText="Search"
2529
onChange={onChange}
@@ -30,10 +34,16 @@ const TableToolbarSearch = ({
3034

3135
TableToolbarSearch.propTypes = {
3236
children: PropTypes.node,
33-
className: PropTypes.string,
37+
3438
/**
3539
* Provide an optional class name for the search container
3640
*/
41+
className: PropTypes.string,
42+
43+
/**
44+
* Provide an optional id for the search container
45+
*/
46+
id: PropTypes.string,
3747
searchContainerClasses: PropTypes.string,
3848

3949
/**

src/components/DataTable/__tests__/DataTable-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('DataTable', () => {
6464
render: jest.fn(({ rows, headers, getHeaderProps, onInputChange }) => (
6565
<TableContainer title="DataTable with toolbar">
6666
<TableToolbar>
67-
<TableToolbarSearch onChange={onInputChange} />
67+
<TableToolbarSearch onChange={onInputChange} id="custom-id" />
6868
<TableToolbarContent>
6969
<TableToolbarAction
7070
iconName="download"

src/components/DataTable/__tests__/TableToolbarSearch-test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import { TableToolbarSearch } from '../';
55
describe('DataTable.TableToolbarSearch', () => {
66
it('should render', () => {
77
const wrapper = mount(
8-
<TableToolbarSearch className="custom-class" onChange={jest.fn()} />
8+
<TableToolbarSearch
9+
className="custom-class"
10+
onChange={jest.fn()}
11+
id="custom-id"
12+
/>
913
);
1014
expect(wrapper).toMatchSnapshot();
1115
});

src/components/DataTable/__tests__/__snapshots__/DataTable-test.js.snap

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -871,13 +871,14 @@ exports[`DataTable should render 1`] = `
871871
className="bx--table-toolbar"
872872
>
873873
<TableToolbarSearch
874+
id="custom-id"
874875
onChange={[Function]}
875876
>
876877
<div
877878
className="bx--toolbar-search-container"
878879
>
879880
<Search
880-
id="search-2"
881+
id="custom-id"
881882
labelText="Filter table"
882883
onChange={[Function]}
883884
placeHolderText="Search"
@@ -921,13 +922,13 @@ exports[`DataTable should render 1`] = `
921922
</Icon>
922923
<label
923924
className="bx--label"
924-
htmlFor="search-2"
925+
htmlFor="custom-id"
925926
>
926927
Filter table
927928
</label>
928929
<input
929930
className="bx--search-input"
930-
id="search-2"
931+
id="custom-id"
931932
onChange={[Function]}
932933
placeholder="Search"
933934
type="text"

src/components/DataTable/__tests__/__snapshots__/TableToolbarSearch-test.js.snap

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
exports[`DataTable.TableToolbarSearch should render 1`] = `
44
<TableToolbarSearch
55
className="custom-class"
6+
id="custom-id"
67
onChange={[MockFunction]}
78
>
89
<div
910
className="bx--toolbar-search-container"
1011
>
1112
<Search
1213
className="custom-class"
13-
id="search-2"
14+
id="custom-id"
1415
labelText="Filter table"
1516
onChange={[MockFunction]}
1617
placeHolderText="Search"
@@ -54,13 +55,13 @@ exports[`DataTable.TableToolbarSearch should render 1`] = `
5455
</Icon>
5556
<label
5657
className="bx--label"
57-
htmlFor="search-2"
58+
htmlFor="custom-id"
5859
>
5960
Filter table
6061
</label>
6162
<input
6263
className="bx--search-input"
63-
id="search-2"
64+
id="custom-id"
6465
onChange={[Function]}
6566
placeholder="Search"
6667
type="text"

0 commit comments

Comments
 (0)