Skip to content

Commit

Permalink
fix(Tooltip): refactor tests from Enzyme to TestingLib (#1553)
Browse files Browse the repository at this point in the history
- Also, `no_animation` not trigger a timeout anymore.
  • Loading branch information
tujoworker authored Sep 6, 2022
1 parent 36b97d3 commit dde8576
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 236 deletions.
12 changes: 10 additions & 2 deletions packages/dnb-eufemia/src/components/tooltip/TooltipPortal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,21 @@ export default class TooltipPortal extends React.PureComponent<
}
})
} else if (!active && prevProps.active) {
tooltipPortal[group].timeout = setTimeout(() => {
const run = () => {
this.setState({ isActive: false }, () => {
if (!this.isMainGorup()) {
this.renderPortal()
}
})
}, parseFloat(String(hide_delay)))
}
if (this.props.no_animation || globalThis.IS_TEST) {
run()
} else {
tooltipPortal[group].timeout = setTimeout(
run,
parseFloat(String(hide_delay))
)
}
}
}
}
Expand Down
22 changes: 12 additions & 10 deletions packages/dnb-eufemia/src/components/tooltip/TooltipWithEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,19 @@ export default class TooltipWithEvents extends React.PureComponent<
warn(e)
}

clearTimeout(this._onEnterTimeout)
this._onEnterTimeout = setTimeout(
() => {
this.setState({ isActive: true })
const run = () => {
this.setState({ isActive: true, clientX: e.clientX })
}

this.setState({ isActive: true, clientX: e.clientX })
},
typeof globalThis !== 'undefined' && !globalThis.IS_TEST
? parseFloat(String(this.props.show_delay)) || 1
: 1
) // have min 1 to make sure we are after onMouseLeave
if (this.props.no_animation || globalThis.IS_TEST) {
run()
} else {
clearTimeout(this._onEnterTimeout)
this._onEnterTimeout = setTimeout(
run,
parseFloat(String(this.props.show_delay)) || 1
) // have min 1 to make sure we are after onMouseLeave
}
}

onMouseLeave = (e: MouseEvent) => {
Expand Down
Loading

0 comments on commit dde8576

Please sign in to comment.