Skip to content

Commit d36fc6e

Browse files
mizgaionutalexandruTarunAdobeRajdeep ChandraRajdeep Chandra
authored
fix(dialog): fade-out animation when lazy loaded on popover overlays (#4937)
* fix(dialog): fade-out animation when lazy loaded on popover overlays * fix(dialog): missing fade-out animations close dispatch * chore: update storybook paragraph * fix: underlay guard * chore: hash update * chore: golden hash update * ci: updated golden image cache * fix: combined decorators * ci: updated golden image cache --------- Co-authored-by: TaraT <[email protected]> Co-authored-by: Rajdeep Chandra <[email protected]> Co-authored-by: Rajdeep Chandra <[email protected]>
1 parent 22fc6d6 commit d36fc6e

File tree

4 files changed

+99
-22
lines changed

4 files changed

+99
-22
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ parameters:
1414
# 3. Commit this change to the PR branch where the changes exist.
1515
current_golden_images_hash:
1616
type: string
17-
default: 62ecc57a00a4e68cdacbad3ce6f0a205fda2e002
17+
default: 167f7d54c17e719f195fa9076629e58da969f9ca
1818
wireit_cache_name:
1919
type: string
2020
default: wireit

packages/dialog/src/DialogBase.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,41 @@ export class DialogBase extends FocusVisiblePolyfillMixin(SpectrumElement) {
155155
this.handleTransitionEvent(event);
156156
}
157157

158+
private get hasTransitionDuration(): boolean {
159+
const modal = this.shadowRoot.querySelector('.modal') as HTMLElement;
160+
161+
const modalTransitionDurations =
162+
window.getComputedStyle(modal).transitionDuration;
163+
for (const duration of modalTransitionDurations.split(','))
164+
if (parseFloat(duration) > 0) return true;
165+
166+
const underlay = this.shadowRoot.querySelector(
167+
'sp-underlay'
168+
) as HTMLElement;
169+
170+
if (underlay) {
171+
const underlayTransitionDurations =
172+
window.getComputedStyle(underlay).transitionDuration;
173+
for (const duration of underlayTransitionDurations.split(','))
174+
if (parseFloat(duration) > 0) return true;
175+
}
176+
177+
return false;
178+
}
179+
158180
protected override update(changes: PropertyValues<this>): void {
159181
if (changes.has('open') && changes.get('open') !== undefined) {
182+
const hasTransitionDuration = this.hasTransitionDuration;
160183
this.animating = true;
161184
this.transitionPromise = new Promise((res) => {
162185
this.resolveTransitionPromise = () => {
163186
this.animating = false;
187+
if (!this.open && hasTransitionDuration)
188+
this.dispatchClosed();
164189
res();
165190
};
166191
});
167-
if (!this.open) {
168-
this.dispatchClosed();
169-
}
192+
if (!this.open && !hasTransitionDuration) this.dispatchClosed();
170193
}
171194
super.update(changes);
172195
}

packages/dialog/stories/dialog-base.stories.ts

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,24 @@ governing permissions and limitations under the License.
1010
*/
1111

1212
import { html, TemplateResult } from '@spectrum-web-components/base';
13-
import '@spectrum-web-components/dialog/sp-dialog-base.js';
14-
import '@spectrum-web-components/dialog/sp-dialog.js';
1513
import '@spectrum-web-components/button/sp-button.js';
16-
import '@spectrum-web-components/overlay/sp-overlay.js';
1714
import '@spectrum-web-components/checkbox/sp-checkbox.js';
15+
import '@spectrum-web-components/dialog/sp-dialog-base.js';
16+
import '@spectrum-web-components/dialog/sp-dialog.js';
17+
import { trigger } from '@spectrum-web-components/overlay';
1818
import { alertDestructive } from './dialog.stories.js';
1919
import { portrait } from './images.js';
20-
import { disabledButtonDecorator } from './index.js';
20+
import {
21+
disabledButtonWithOverlayDecorator,
22+
withOverlayDecorator,
23+
} from './index.js';
2124

2225
export default {
2326
title: 'Dialog Base',
2427
component: 'sp-dialog-base',
25-
decorators: [
26-
(story: () => TemplateResult): TemplateResult => {
27-
return html`
28-
<sp-button variant="primary" id="trigger">
29-
Toggle Dialog
30-
</sp-button>
31-
<sp-overlay type="modal" trigger="trigger@click" open>
32-
${story()}
33-
</sp-overlay>
34-
`;
35-
},
36-
],
3728
};
3829

39-
export const Slotted = (): TemplateResult => html`
30+
export const slotted = (): TemplateResult => html`
4031
<sp-dialog-base
4132
underlay
4233
@click=${(event: Event) => {
@@ -50,6 +41,7 @@ export const Slotted = (): TemplateResult => html`
5041
${alertDestructive()}
5142
</sp-dialog-base>
5243
`;
44+
slotted.decorators = [withOverlayDecorator];
5345

5446
export const disabledButton = (): TemplateResult => {
5547
return html`
@@ -116,7 +108,7 @@ export const disabledButton = (): TemplateResult => {
116108
`;
117109
};
118110

119-
disabledButton.decorators = [disabledButtonDecorator];
111+
disabledButton.decorators = [disabledButtonWithOverlayDecorator];
120112

121113
export const notAgain = (): TemplateResult => html`
122114
<sp-dialog-base
@@ -143,6 +135,7 @@ export const notAgain = (): TemplateResult => html`
143135
</sp-dialog>
144136
</sp-dialog-base>
145137
`;
138+
notAgain.decorators = [withOverlayDecorator];
146139

147140
export const moreCustom = (): TemplateResult => html`
148141
<sp-dialog-base
@@ -189,6 +182,7 @@ export const moreCustom = (): TemplateResult => html`
189182
</div>
190183
</sp-dialog-base>
191184
`;
185+
moreCustom.decorators = [withOverlayDecorator];
192186

193187
export const fullyCustom = (): TemplateResult => html`
194188
<sp-dialog-base
@@ -222,3 +216,46 @@ export const fullyCustom = (): TemplateResult => html`
222216
</div>
223217
</sp-dialog-base>
224218
`;
219+
fullyCustom.decorators = [withOverlayDecorator];
220+
221+
export const lazyLoaded = (): TemplateResult => {
222+
const template = (): TemplateResult => html`
223+
<sp-dialog-base
224+
underlay
225+
@click=${(event: Event) => {
226+
if ((event.target as HTMLElement).localName === 'sp-button') {
227+
(event.target as HTMLElement).dispatchEvent(
228+
new Event('close', { bubbles: true, composed: true })
229+
);
230+
}
231+
}}
232+
>
233+
<sp-dialog size="m">
234+
<h2 slot="heading">This is a heading</h2>
235+
<p>
236+
The click on the "OK" button should close the overlay with
237+
the correct animation (duration).
238+
</p>
239+
<sp-button variant="secondary" treatment="fill" slot="button">
240+
Ok
241+
</sp-button>
242+
</sp-dialog>
243+
</sp-dialog-base>
244+
`;
245+
246+
return html`
247+
<sp-button
248+
variant="primary"
249+
${trigger(template, {
250+
open: false,
251+
triggerInteraction: 'click',
252+
})}
253+
>
254+
Open dialog
255+
</sp-button>
256+
`;
257+
};
258+
259+
lazyLoaded.swc_vrt = {
260+
skip: true,
261+
};

packages/dialog/stories/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ governing permissions and limitations under the License.
1111
*/
1212

1313
import { html, TemplateResult } from '@spectrum-web-components/base';
14+
import '@spectrum-web-components/button/sp-button.js';
15+
import '@spectrum-web-components/overlay/sp-overlay.js';
1416

1517
class CountdownWatcher extends HTMLElement {
1618
ready!: (value: boolean | PromiseLike<boolean>) => void;
@@ -43,3 +45,18 @@ export const disabledButtonDecorator = (
4345
<countdown-complete-watcher></countdown-complete-watcher>
4446
`;
4547
};
48+
49+
export const withOverlayDecorator = (
50+
story: () => TemplateResult
51+
): TemplateResult => {
52+
return html`
53+
<sp-button variant="primary" id="trigger">Toggle Dialog</sp-button>
54+
<sp-overlay type="modal" trigger="trigger@click" open>
55+
${story()}
56+
</sp-overlay>
57+
`;
58+
};
59+
60+
export const disabledButtonWithOverlayDecorator = (
61+
story: () => TemplateResult
62+
): TemplateResult => withOverlayDecorator(() => disabledButtonDecorator(story));

0 commit comments

Comments
 (0)