From ed0577f4b19ea72ffeea082462f4868f4f5b3cd1 Mon Sep 17 00:00:00 2001 From: Robert Lukasonok <70327485+roluk@users.noreply.github.com> Date: Tue, 1 Mar 2022 12:54:26 +0200 Subject: [PATCH 1/2] Remove workaround for checkbox bug --- ui/core-react/src/core-react/tree/Node.tsx | 33 ++++------------------ ui/core-react/src/test/tree/Node.test.tsx | 2 +- 2 files changed, 7 insertions(+), 28 deletions(-) diff --git a/ui/core-react/src/core-react/tree/Node.tsx b/ui/core-react/src/core-react/tree/Node.tsx index bb5fb943f046..32ac58f75ebc 100644 --- a/ui/core-react/src/core-react/tree/Node.tsx +++ b/ui/core-react/src/core-react/tree/Node.tsx @@ -85,8 +85,6 @@ export interface TreeNodeProps extends CommonProps { * @public */ export class TreeNode extends React.Component { - private checkboxWrapperRef = React.createRef(); - constructor(props: TreeNodeProps) { super(props); } @@ -117,13 +115,11 @@ export class TreeNode extends React.Component { checkbox = this.props.renderOverrides.renderCheckbox(props); } else { checkbox = ( -
- ) => this._onCheckboxChange(e.target.checked)} - data-testid={this.createSubComponentTestId("checkbox")} - /> -
+ ) => this._onCheckboxChange(e.target.checked)} + data-testid={this.createSubComponentTestId("checkbox")} + /> ); } } @@ -192,23 +188,6 @@ export class TreeNode extends React.Component { private _onClick = (e: React.MouseEvent) => { e.stopPropagation(); - - // ITwinUI-react has a bug that prevents us from stopping checkbox click event propagation to the parent element - if (!this.checkboxWrapperRef.current - || (e.target instanceof Element && !isDescendant(this.checkboxWrapperRef.current, e.target))) { - this.props.onClick?.(e); - } + this.props.onClick?.(e); }; } - -function isDescendant(ancestor: Element, descendant: Element): boolean { - while (descendant.parentElement !== null) { - if (descendant === ancestor) { - return true; - } - - descendant = descendant.parentElement; - } - - return false; -} diff --git a/ui/core-react/src/test/tree/Node.test.tsx b/ui/core-react/src/test/tree/Node.test.tsx index 0b6c525d631d..6c4126f46469 100644 --- a/ui/core-react/src/test/tree/Node.test.tsx +++ b/ui/core-react/src/test/tree/Node.test.tsx @@ -133,7 +133,7 @@ describe("", () => { it("does not call node onClick callback when checkbox is clicked", () => { const handleOnClick = sinon.fake(); const { getByRole } = render(); - fireEvent.click(getByRole("checkbox").parentElement!); + fireEvent.click(getByRole("checkbox")); expect(handleOnClick).to.not.have.been.called; }); From 2eb4d388ea4b5781071cc288e1e8f8f68e88502e Mon Sep 17 00:00:00 2001 From: Robert Lukasonok <70327485+roluk@users.noreply.github.com> Date: Tue, 1 Mar 2022 13:22:52 +0200 Subject: [PATCH 2/2] rush change --- .../ui-checkbox-workaround_2022-03-01-11-21.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 common/changes/@itwin/core-react/ui-checkbox-workaround_2022-03-01-11-21.json diff --git a/common/changes/@itwin/core-react/ui-checkbox-workaround_2022-03-01-11-21.json b/common/changes/@itwin/core-react/ui-checkbox-workaround_2022-03-01-11-21.json new file mode 100644 index 000000000000..53d132ff2356 --- /dev/null +++ b/common/changes/@itwin/core-react/ui-checkbox-workaround_2022-03-01-11-21.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@itwin/core-react", + "comment": "", + "type": "none" + } + ], + "packageName": "@itwin/core-react" +}