Skip to content

Commit

Permalink
fix freezing
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed May 19, 2021
1 parent 47b4e0c commit c1ae0f8
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 33 deletions.
97 changes: 70 additions & 27 deletions src-docs/src/views/datagrid/virtualization_constrained.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import {
EuiLink,
EuiText,
EuiResizableContainer,
EuiButton,
EuiFlyout,
EuiFlyoutHeader,
EuiFlyoutBody,
EuiTitle,
} from '../../../../src/components/';

const DataContext = createContext();
Expand Down Expand Up @@ -125,6 +130,39 @@ export default () => {
[]
);

const [isFlyoutVisible, setIsFlyoutVisible] = useState(false);

const closeFlyout = () => setIsFlyoutVisible(false);

const toggleFlyout = () => setIsFlyoutVisible((isVisible) => !isVisible);

const flyoutTitleId = 'myid';

let flyout;
if (isFlyoutVisible) {
flyout = (
<EuiFlyout
ownFocus={false}
onClose={closeFlyout}
outsideClickCloses={true}
aria-labelledby={flyoutTitleId}>
<EuiFlyoutHeader hasBorder>
<EuiTitle size="s">
<h2 id={flyoutTitleId}>A flyout without ownFocus</h2>
</EuiTitle>
</EuiFlyoutHeader>
<EuiFlyoutBody>
<EuiText>
<p>
The page contents is still interactable though screenreader users
will find themselves still within the bounds of the flyout.
</p>
</EuiText>
</EuiFlyoutBody>
</EuiFlyout>
);
}

const grid = (
<EuiDataGrid
aria-label="Virtualized data grid demo"
Expand All @@ -142,32 +180,37 @@ export default () => {
);

return (
<DataContext.Provider value={dataContext}>
<EuiText>
<p>There are {mountedCellCount} rendered cells</p>
</EuiText>

<EuiResizableContainer style={{ height: '400px' }}>
{(EuiResizablePanel, EuiResizableButton) => (
<>
<EuiResizablePanel initialSize={50} minSize="30%">
{grid}
</EuiResizablePanel>

<EuiResizableButton />

<EuiResizablePanel initialSize={50} minSize="200px">
<EuiText>
<p>
This panel is constraining the datagrid. You can resize it
using the drag handle and <strong>EuiDataGrid</strong>{' '}
automatically detects the changes to its container size.
</p>
</EuiText>
</EuiResizablePanel>
</>
)}
</EuiResizableContainer>
</DataContext.Provider>
<div>
<EuiButton onClick={toggleFlyout}>Toggle flyout</EuiButton>

{flyout}
<DataContext.Provider value={dataContext}>
<EuiText>
<p>There are {mountedCellCount} rendered cells</p>
</EuiText>

<EuiResizableContainer style={{ height: '400px' }}>
{(EuiResizablePanel, EuiResizableButton) => (
<>
<EuiResizablePanel initialSize={50} minSize="30%">
{grid}
</EuiResizablePanel>

<EuiResizableButton />

<EuiResizablePanel initialSize={50} minSize="200px">
<EuiText>
<p>
This panel is constraining the datagrid. You can resize it
using the drag handle and <strong>EuiDataGrid</strong>{' '}
automatically detects the changes to its container size.
</p>
</EuiText>
</EuiResizablePanel>
</>
)}
</EuiResizableContainer>
</DataContext.Provider>
</div>
);
};
14 changes: 8 additions & 6 deletions src/components/datagrid/data_grid_cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,15 @@ export class EuiDataGridCell extends Component<
// event up, which can trigger the focus() call below, causing focus lock fighting
if (this.cellRef.current === e.target) {
const { colIndex, visibleRowIndex, isExpandable } = this.props;
this.context.setFocusedCell([colIndex, visibleRowIndex]);
setTimeout(() => {
this.context.setFocusedCell([colIndex, visibleRowIndex]);

const interactables = this.getInteractables();
if (interactables.length === 1 && isExpandable === false) {
interactables[0].focus();
this.setState({ disableCellTabIndex: true });
}
const interactables = this.getInteractables();
if (interactables.length === 1 && isExpandable === false) {
interactables[0].focus();
this.setState({ disableCellTabIndex: true });
}
}, 0);
}
};

Expand Down
1 change: 1 addition & 0 deletions src/components/flyout/flyout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ const EuiFlyout = forwardRef(
</Element>
);

console.log('rendering flyout with focus trap disabled: ' + isPushed);
/*
* Trap focus even when `ownFocus={false}`, otherwise closing
* the flyout won't return focus to the originating button.
Expand Down

0 comments on commit c1ae0f8

Please sign in to comment.