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

[EuiBasicTable] Fix generated IDs regenerating on rerender #5196

Merged
merged 2 commits into from
Sep 20, 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
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}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before:
select_all_checkbox_before

After:
select_all_checkbox_after

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();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before:
basic_table_action_before

After:
basic_table_action_after

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