Skip to content

Commit

Permalink
[EuiBasicTable] Fix generated IDs regenerating on rerender (#5196)
Browse files Browse the repository at this point in the history
* [Fix] BasicTable DefaultItemAction generated ID

* Fix Select All checkbox ID
  • Loading branch information
Constance authored Sep 20, 2021
1 parent bf72cba commit 571ebc4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/components/basic_table/basic_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ export class EuiBasicTable<T = any> extends Component<
}

tableId = htmlIdGenerator('__table')();
selectAllCheckboxId = htmlIdGenerator('_selection_column-checkbox')();

render() {
const {
Expand Down Expand Up @@ -762,7 +763,7 @@ export class EuiBasicTable<T = any> extends Component<
<EuiI18n token="euiBasicTable.selectAllRows" default="Select all rows">
{(selectAllRows: string) => (
<EuiCheckbox
id={`_selection_column-checkbox_${htmlIdGenerator()()}`}
id={this.selectAllCheckboxId}
type={isMobile ? undefined : 'inList'}
checked={checked}
disabled={disabled}
Expand Down
4 changes: 2 additions & 2 deletions src/components/basic_table/default_item_action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '../button';
import { EuiToolTip } from '../tool_tip';
import { DefaultItemAction as Action } from './action_types';
import { htmlIdGenerator } from '../../services/accessibility';
import { useGeneratedHtmlId } from '../../services/accessibility';
import { EuiScreenReaderOnly } from '../accessibility';

export interface DefaultItemActionProps<T> {
Expand Down Expand Up @@ -57,12 +57,12 @@ export const DefaultItemAction = <T extends {}>({
let button;
const actionContent =
typeof action.name === 'function' ? action.name(item) : action.name;
const ariaLabelId = useGeneratedHtmlId();
if (action.type === 'icon') {
if (!icon) {
throw new Error(`Cannot render item action [${action.name}]. It is configured to render as an icon but no
icon is provided. Make sure to set the 'icon' property of the action`);
}
const ariaLabelId = htmlIdGenerator()();
button = (
<>
<EuiButtonIcon
Expand Down

0 comments on commit 571ebc4

Please sign in to comment.