Skip to content

Commit 7eb4929

Browse files
authored
Merge pull request #2277 from pie-framework/fix/PIE-575
fix(editable-html-tip-tap): prevent toolbar closing when clicking the…
2 parents 54d3672 + 1b38e20 commit 7eb4929

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

packages/editable-html-tip-tap/src/components/__tests__/InlineDropdown.test.jsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,20 @@ describe('InlineDropdown', () => {
464464
expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
465465
});
466466

467+
it('does not close toolbar when clicking the page scrollbar (documentElement)', async () => {
468+
const { queryByTestId } = render(<InlineDropdown {...defaultProps} selected={true} />);
469+
470+
await waitFor(() => {
471+
expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
472+
});
473+
474+
fireEvent.mouseDown(document.documentElement);
475+
476+
await waitFor(() => {
477+
expect(queryByTestId('inline-dropdown-toolbar')).toBeInTheDocument();
478+
});
479+
});
480+
467481
it('renders delete control on portaled custom toolbar when container el is set', async () => {
468482
const { findByLabelText } = render(<InlineDropdown {...defaultProps} selected />);
469483
expect(await findByLabelText('Delete')).toBeInTheDocument();

packages/editable-html-tip-tap/src/components/respArea/InlineDropdown.jsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ const InlineDropdown = (props) => {
9393
}
9494
}, [editor, node, selected]);
9595

96+
97+
98+
const isScrollbarClicked = (event) =>
99+
event.clientX > document.documentElement.clientWidth ||
100+
event.clientY > document.documentElement.clientHeight ||
101+
event.target === document.documentElement;
102+
103+
96104
useEffect(() => {
97105
// Calculate position relative to selection
98106
const bodyRect = document.body.getBoundingClientRect();
@@ -105,6 +113,10 @@ const InlineDropdown = (props) => {
105113
});
106114

107115
const handleClickOutside = (event) => {
116+
117+
if( isScrollbarClicked(event) ) {
118+
return;
119+
}
108120
const insideSomeEditor = event.target.closest('[data-toolbar-for]');
109121

110122
if (

0 commit comments

Comments
 (0)