Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions src-docs/src/views/tables/basic/basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export default () => {
columns={columns}
rowProps={getRowProps}
cellProps={getCellProps}
loading
/>
);
};
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`