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
5 changes: 5 additions & 0 deletions src/components/datagrid/body/data_grid_cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,11 @@ export class EuiDataGridCell extends Component<
interactables[0].focus();
this.setState({ disableCellTabIndex: true });
}

// Close the cell popover if the popover was open and the user clicked the cell
if (this.props.popoverContext.popoverIsOpen) {
this.props.popoverContext.closeCellPopover();
}

@thompsongl thompsongl Apr 14, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Based on the comment, should this be in onClick instead of onFocus? Or is onFocus an analog for a click event in the context of a data grid cell?

@cee-chen cee-chen Apr 14, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Each data grid cell is clickable/focusable so onFocus will also fire on clicks. I don't think it's super necessary to specify a separate onClick event - in theory the only realistic way that a user could focus the cell while the popover is open is through either clicking or tapping the cell (keyboard users should not be able to exit the popover in theory, but it is possible if the focus trap has been broken).

I'm also bogarting the existing onFocus event because it has a nice event.target check that I also want for this behavior (i.e. only firing on the cell parent and not on cell children focus).

tl;dr there's no real downside to using onFocus, it's broader and will catch more possible side effects/users, even if the main use case is mouse clicks

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

in theory the only realistic way that a user could focus the cell while the popover is open is through either clicking or tapping the cell

That's kind of what I was thinking too. Sounds good

},
0
);
Expand Down
17 changes: 17 additions & 0 deletions src/components/datagrid/body/data_grid_cell_popover.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,21 @@ describe('EuiDataGridCellPopover', () => {
.should('have.attr', 'data-gridcell-row-index', '1');
});
});

it('closes the cell popover when the originating cell is clicked', () => {
cy.realMount(<EuiDataGrid {...baseProps} />);
cy.get(
'[data-gridcell-row-index="0"][data-gridcell-column-index="0"]'
).realClick();

cy.get('[data-test-subj="euiDataGridCellExpandButton"]').realClick();
cy.get('[data-test-subj="euiDataGridExpansionPopover"]').should('exist');

cy.get(
'[data-gridcell-row-index="0"][data-gridcell-column-index="0"]'
).realClick();
cy.get('[data-test-subj="euiDataGridExpansionPopover"]').should(
'not.exist'
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ describe('useCellPopover', () => {
hasArrow={false}
isOpen={true}
onKeyDown={[Function]}
onTrapDeactivation={[Function]}
panelClassName="euiDataGridRowCell__popover"
panelPaddingSize="s"
panelProps={
Expand Down
1 change: 0 additions & 1 deletion src/components/datagrid/body/data_grid_cell_popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ export const useCellPopover = (): {
'data-test-subj': 'euiDataGridExpansionPopover',
}}
closePopover={closeCellPopover}
onTrapDeactivation={closeCellPopover}
onKeyDown={(event) => {
if (event.key === keys.F2 || event.key === keys.ESCAPE) {
event.preventDefault();
Expand Down
3 changes: 3 additions & 0 deletions upcoming_changelogs/5797.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**Bug fixes**

- Fixed an `EuiDataGrid` bug occurring when closing cell popovers on clicking the originating cell. The original fix was unintentionally affecting cell popovers with nested modals, popovers, etc.