Skip to content

Commit

Permalink
FIX Popover toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Aug 3, 2023
1 parent 177c9ad commit 75ed246
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion client/src/components/ActionMenu/ActionMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ class ActionMenu extends PureComponent {

// Force setting state to the end of the execution queue to clear a potential race condition
// with entwine click handlers
window.setTimeout(() => this.setState((prevState) => ({ isOpen: !prevState.isOpen })), 0);
//
// eslint disable the next line which references this.state within setState()
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-access-state-in-setstate.md
// Following eslint guidelines this would be implemented as:
// window.setTimeout(() => this.setState((prevState) => ({ isOpen: !prevState.isOpen })), 0);
// However react ends up confused it's wrapped inside window.setTimeout()
// and it may end up setting state twice causing the toggle to open and then immediately close
// eslint-disable-next-line
window.setTimeout(() => this.setState({ isOpen: !this.state.isOpen }), 0);
}

render() {
Expand Down
10 changes: 9 additions & 1 deletion client/src/components/PopoverField/PopoverField.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,15 @@ class PopoverField extends Component {

// Force setting state to the end of the execution queue to clear a potential race condition
// with entwine click handlers
window.setTimeout(() => this.setState((prevState) => ({ isOpen: !prevState.isOpen }), toggleCallback), 0);
//
// eslint disable the next line which references this.state within setState()
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-access-state-in-setstate.md
// Following eslint guidelines this would be implemented as:
// window.setTimeout(() => this.setState((prevState) => ({ isOpen: !prevState.isOpen }), toggleCallback), 0);
// However react ends up confused it's wrapped inside window.setTimeout()
// and it may end up setting state twice causing the toggle to open and then immediately close
// eslint-disable-next-line
window.setTimeout(() => this.setState({ isOpen: !this.state.isOpen }, toggleCallback), 0);
}

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ class PopoverOptionSetToggle extends Component {
handleToggle() {
// Force setting state to the end of the execution queue to clear a potential race condition
// with entwine click handlers
window.setTimeout(() => this.setState((prevState) => ({ isOpen: !prevState.isOpen })), 0);
//
// eslint disable the next line which references this.state within setState()
// https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-access-state-in-setstate.md
// Following eslint guidelines this would be implemented as:
// window.setTimeout(() => this.setState((prevState) => ({ isOpen: !prevState.isOpen })), 0);
// However react ends up confused it's wrapped inside window.setTimeout()
// and it may end up setting state twice causing the toggle to open and then immediately close
// eslint-disable-next-line
window.setTimeout(() => this.setState({ isOpen: !this.state.isOpen }), 0);
}

render() {
Expand Down

0 comments on commit 75ed246

Please sign in to comment.