From 2e272a63d25a5225e2c253cf2b5b8cecefaa6d80 Mon Sep 17 00:00:00 2001 From: Jane Chu <7559015+janechu@users.noreply.github.com> Date: Wed, 31 Mar 2021 12:33:57 -0700 Subject: [PATCH] fix: remove the use of detail as this is a synthetic event value and will not be compatible with React 17 (#4515) # Description Removed the check using `detail` and resolve whether a click is a single or double click using only `setTimeout`. ## Motivation & context The use of the synthetic events `detail` would occasionally result in console logs being generated from React. Due to this also being removed in React 17 the double click detection is remediated to work solely from `setTimeout`. ## Issue type checklist - [ ] **Chore**: A change that does not impact distributed packages. - [x] **Bug fix**: A change that fixes an issue, link to the issue above. - [ ] **New feature**: A change that adds functionality. **Is this a breaking change?** - [ ] This change causes current functionality to break. **Adding or modifying component(s) in `@microsoft/fast-components` checklist** - [ ] I have added a new component - [ ] I have modified an existing component - [ ] I have updated the [definition file](https://github.com/Microsoft/fast/blob/master/packages/web-components/fast-components/CONTRIBUTING.md#definition) - [ ] I have updated the [configuration file](https://github.com/Microsoft/fast/blob/master/packages/web-components/fast-components/CONTRIBUTING.md#configuration) ## Process & policy checklist - [ ] I have added tests for my changes. - [x] I have tested my changes. - [ ] I have updated the project documentation to reflect my changes. - [x] I have read the [CONTRIBUTING](https://github.com/Microsoft/fast/blob/master/CONTRIBUTING.md) documentation and followed the [standards](https://www.fast.design/docs/community/code-of-conduct/#our-standards) for this project. --- .../src/navigation/navigation.tsx | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/packages/tooling/fast-tooling-react/src/navigation/navigation.tsx b/packages/tooling/fast-tooling-react/src/navigation/navigation.tsx index fb343420f6b..bab1f91d128 100644 --- a/packages/tooling/fast-tooling-react/src/navigation/navigation.tsx +++ b/packages/tooling/fast-tooling-react/src/navigation/navigation.tsx @@ -596,21 +596,27 @@ class Navigation extends Foundation< navigationConfigId: string ): ((event: React.MouseEvent) => void) => { let timer; + let timesClicked = 0; return (event: React.MouseEvent): void => { clearTimeout(timer); + timesClicked += 1; - if (event.detail === 1) { - timer = setTimeout( + setTimeout(() => { + if (timesClicked === 1) { this.handleNavigationItemSingleClick( dictionaryId, navigationConfigId - ), - 200 - ); - } else if (event.detail === 2) { - this.handleNavigationItemDoubleClick(dictionaryId, navigationConfigId)(); - } + ); + } else if (timesClicked === 2) { + this.handleNavigationItemDoubleClick( + dictionaryId, + navigationConfigId + ); + } + + timesClicked = 0; + }, 200); }; }; @@ -620,10 +626,8 @@ class Navigation extends Foundation< private handleNavigationItemSingleClick = ( dictionaryId: string, navigationConfigId: string - ): (() => void) => { - return (): void => { - this.triggerNavigationUpdate(dictionaryId, navigationConfigId); - }; + ): void => { + this.triggerNavigationUpdate(dictionaryId, navigationConfigId); }; /** @@ -632,12 +636,10 @@ class Navigation extends Foundation< private handleNavigationItemDoubleClick = ( dictionaryId: string, navigationConfigId: string - ): (() => void) => { - return (): void => { - if (this.isEditable(dictionaryId, navigationConfigId)) { - this.triggerNavigationEdit(); - } - }; + ): void => { + if (this.isEditable(dictionaryId, navigationConfigId)) { + this.triggerNavigationEdit(); + } }; /**