Skip to content

Commit

Permalink
fix(StepIndicator): fix height animation issue when CSS is loaded too…
Browse files Browse the repository at this point in the history
… slow (#1221)
  • Loading branch information
tujoworker authored Jan 31, 2022
1 parent 6b5ddcf commit 8dfdd7e
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default class StepIndicatorTriggerButton extends React.PureComponent {

componentDidMount() {
this._heightAnim.setElement(this._buttonRef.current)
this._prevStep = this.context.activeStep
}

componentWillUnmount() {
Expand All @@ -61,14 +62,9 @@ export default class StepIndicatorTriggerButton extends React.PureComponent {
if (this._prevStep !== this.context.activeStep) {
const toHeight = this._heightAnim.getUnknownHeight()

// make animation smooth
// because we set the height before requestAnimationFrame
// also, to ensure smoothness, the parent li wrapper (&__trigger) needs flex column
this._heightAnim.adjustFrom(height)

this._heightAnim.adjustTo(height, toHeight)
this._prevStep = this.context.activeStep
}
this._prevStep = this.context.activeStep
}

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2171,7 +2171,6 @@ Array [
aria-describedby="unique-id-loose-snapshot-overview"
class="dnb-button dnb-button--secondary dnb-button--has-text dnb-step-indicator__trigger__button dnb-button--icon-position-right dnb-button--has-icon dnb-button--icon-size-medium dnb-button--stretch dnb-button--wrap"
id="unique-id-loose-snapshot"
style="height: auto;"
type="button"
>
<span
Expand Down Expand Up @@ -2288,7 +2287,6 @@ Array [
aria-describedby="unique-id-loose-snapshot-overview"
class="dnb-button dnb-button--secondary dnb-button--has-text dnb-step-indicator__trigger__button dnb-button--icon-position-right dnb-button--has-icon dnb-button--icon-size-medium dnb-button--stretch dnb-button--wrap"
id="unique-id-loose-snapshot"
style="height: auto;"
type="button"
>
<span
Expand Down Expand Up @@ -2402,7 +2400,6 @@ Array [
aria-describedby="unique-id-loose-snapshot-overview"
class="dnb-button dnb-button--secondary dnb-button--has-text dnb-step-indicator__trigger__button dnb-button--icon-position-right dnb-button--has-icon dnb-button--icon-size-medium dnb-button--stretch dnb-button--wrap"
id="unique-id-loose-snapshot"
style="height: auto;"
type="button"
>
<span
Expand Down Expand Up @@ -4787,7 +4784,6 @@ Array [
aria-describedby="unique-id-static-snapshot-overview"
class="dnb-button dnb-button--secondary dnb-button--has-text dnb-step-indicator__trigger__button dnb-button--icon-position-right dnb-button--has-icon dnb-button--icon-size-medium dnb-button--stretch dnb-button--wrap"
id="unique-id-static-snapshot"
style="height: auto;"
type="button"
>
<span
Expand Down Expand Up @@ -4904,7 +4900,6 @@ Array [
aria-describedby="unique-id-static-snapshot-overview"
class="dnb-button dnb-button--secondary dnb-button--has-text dnb-step-indicator__trigger__button dnb-button--icon-position-right dnb-button--has-icon dnb-button--icon-size-medium dnb-button--stretch dnb-button--wrap"
id="unique-id-static-snapshot"
style="height: auto;"
type="button"
>
<span
Expand Down Expand Up @@ -5018,7 +5013,6 @@ Array [
aria-describedby="unique-id-static-snapshot-overview"
class="dnb-button dnb-button--secondary dnb-button--has-text dnb-step-indicator__trigger__button dnb-button--icon-position-right dnb-button--has-icon dnb-button--icon-size-medium dnb-button--stretch dnb-button--wrap"
id="unique-id-static-snapshot"
style="height: auto;"
type="button"
>
<span
Expand Down Expand Up @@ -7417,7 +7411,6 @@ Array [
aria-describedby="unique-id-strict-snapshot-overview"
class="dnb-button dnb-button--secondary dnb-button--has-text dnb-step-indicator__trigger__button dnb-button--icon-position-right dnb-button--has-icon dnb-button--icon-size-medium dnb-button--stretch dnb-button--wrap"
id="unique-id-strict-snapshot"
style="height: auto;"
type="button"
>
<span
Expand Down Expand Up @@ -7534,7 +7527,6 @@ Array [
aria-describedby="unique-id-strict-snapshot-overview"
class="dnb-button dnb-button--secondary dnb-button--has-text dnb-step-indicator__trigger__button dnb-button--icon-position-right dnb-button--has-icon dnb-button--icon-size-medium dnb-button--stretch dnb-button--wrap"
id="unique-id-strict-snapshot"
style="height: auto;"
type="button"
>
<span
Expand Down Expand Up @@ -7648,7 +7640,6 @@ Array [
aria-describedby="unique-id-strict-snapshot-overview"
class="dnb-button dnb-button--secondary dnb-button--has-text dnb-step-indicator__trigger__button dnb-button--icon-position-right dnb-button--has-icon dnb-button--icon-size-medium dnb-button--stretch dnb-button--wrap"
id="unique-id-strict-snapshot"
style="height: auto;"
type="button"
>
<span
Expand Down
30 changes: 17 additions & 13 deletions packages/dnb-eufemia/src/shared/AnimateHeight.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ export default class AnimateHeight {
this.onCloseEnd = null
}
}
_emitTransitionEnd() {
try {
const event = new CustomEvent('transitionend')
this.elem.dispatchEvent(event)
} catch (e) {
warn(e)
}
}

// Public methods
setElement(elem, container = null) {
Expand Down Expand Up @@ -127,24 +135,20 @@ export default class AnimateHeight {
this.onEndStack.push(fn)
}
start(fromHeight, toHeight, { animate = true } = {}) {
try {
if (window.location.href.includes('data-visual-test')) {
animate = false
}
} catch (e) {
//
if (window?.location?.href?.includes('data-visual-test')) {
animate = false
}

if (animate === false || this.opts?.animate === false) {
if (
fromHeight === toHeight ||
animate === false ||
this.opts?.animate === false
) {
this.elem.style.height = `${toHeight}px`

this._callOnStart()

try {
const event = new CustomEvent('transitionend')
this.elem.dispatchEvent(event)
} catch (e) {
warn(e)
}
this._emitTransitionEnd()

return // stop here
}
Expand Down
Loading

0 comments on commit 8dfdd7e

Please sign in to comment.