Skip to content

Commit

Permalink
fix: fix open/close event emitting in Safari (#7551)
Browse files Browse the repository at this point in the history
**Related Issue:** #7180

## Summary

This updates how `onToggleOpenCloseComponent` determines the duration
for the `openTransitionProp` to be more robust to work consistently
across browsers.

The previous approach relied on the computed `transition` property
having all associated transition values laid out per prop, which didn't
work in Safari since it won't include all values if shared.

This change should be covered by existing tests.

cc @Elijbet
  • Loading branch information
jcfranco authored Aug 18, 2023
1 parent 8960126 commit a68b053
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/calcite-components/src/utils/openCloseComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,18 @@ function emitImmediately(component: OpenCloseComponent, nonOpenCloseComponent =
export function onToggleOpenCloseComponent(component: OpenCloseComponent, nonOpenCloseComponent = false): void {
readTask((): void => {
if (component.transitionEl) {
const allTransitionPropsArray = getComputedStyle(component.transitionEl).transition.split(" ");
const openTransitionPropIndex = allTransitionPropsArray.findIndex(
(item) => item === component.openTransitionProp
const { transitionDuration: allDurations, transitionProperty: allProps } = getComputedStyle(
component.transitionEl
);
const transitionDuration = allTransitionPropsArray[openTransitionPropIndex + 1];
const allTransitionDurationsArray = allDurations.split(",");
const allTransitionPropsArray = allProps.split(",");
const openTransitionPropIndex = allTransitionPropsArray.indexOf(component.openTransitionProp);

const transitionDuration =
allTransitionDurationsArray[openTransitionPropIndex] ??
/* Safari will have a single transition value if multiple props share it,
so we fall back to it if there's no matching prop duration */
allTransitionDurationsArray[0];

if (transitionDuration === "0s") {
emitImmediately(component, nonOpenCloseComponent);
Expand Down

0 comments on commit a68b053

Please sign in to comment.