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] Remove preventing all mouse/keyboard interactions when loading #6543

Merged
merged 4 commits into from
Jan 24, 2023
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
66 changes: 2 additions & 64 deletions src/components/basic_table/basic_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,6 @@ export class EuiBasicTable<T = any> extends Component<
return null;
}

// used for moving in & out of `loading` state
private cleanups: Array<() => void> = [];
private tbody: HTMLTableSectionElement | null = null;

constructor(props: EuiBasicTableProps<T>) {
super(props);
this.state = {
Expand All @@ -363,25 +359,13 @@ export class EuiBasicTable<T = any> extends Component<
}

componentDidMount() {
if (this.props.loading && this.tbody) this.addLoadingListeners(this.tbody);
this.getInitialSelection();
}

componentDidUpdate(prevProps: EuiBasicTableProps<T>) {
if (prevProps.loading !== this.props.loading) {
if (this.props.loading && this.tbody) {
this.addLoadingListeners(this.tbody);
} else {
this.removeLoadingListeners();
}
}
componentDidUpdate() {
this.getInitialSelection();
}

componentWillUnmount() {
this.removeLoadingListeners();
}

getInitialSelection() {
if (
this.props.selection &&
Expand All @@ -398,49 +382,6 @@ export class EuiBasicTable<T = any> extends Component<
this.changeSelection(newSelection);
}

private setTbody = (tbody: HTMLTableSectionElement | null) => {
// remove listeners from an existing element
this.removeLoadingListeners();

// update the ref
this.tbody = tbody;

// if loading, add listeners
if (this.props.loading === true && tbody) {
this.addLoadingListeners(tbody);
}
};

private addLoadingListeners = (tbody: HTMLTableSectionElement) => {
const listener = (event: Event) => {
event.stopPropagation();
event.preventDefault();
};
[
'mousedown',
'mouseup',
'mouseover',
'mouseout',
'mouseenter',
'mouseleave',
'click',
'dblclick',
'keydown',
'keyup',
'keypress',
].forEach((event) => {
tbody.addEventListener(event, listener, true);
this.cleanups.push(() => {
tbody.removeEventListener(event, listener, true);
});
});
};

private removeLoadingListeners = () => {
this.cleanups.forEach((cleanup) => cleanup());
this.cleanups.length = 0;
};

buildCriteria(props: EuiBasicTableProps<T>): Criteria<T> {
const criteria: Criteria<T> = {};
if (hasPagination(props)) {
Expand Down Expand Up @@ -969,10 +910,7 @@ export class EuiBasicTable<T = any> extends Component<
return (
<RenderWithEuiTheme>
{(theme) => (
<EuiTableBody
bodyRef={this.setTbody}
css={loading && euiBasicTableBodyLoading(theme)}
>
<EuiTableBody css={loading && euiBasicTableBodyLoading(theme)}>
{content}
</EuiTableBody>
)}
Expand Down
3 changes: 3 additions & 0 deletions upcoming_changelogs/6543.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**Breaking changes**

- `EuiBasicTable` no longer blocks mouse/keyboard interactions while `loading`