Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(toast): switches toast[open] to use visibility hidden to fix overlay handling #3511

Merged
merged 4 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 19 additions & 2 deletions packages/toast/src/toast.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@ governing permissions and limitations under the License.

@import './spectrum-toast.css';

:host(:not([open])) {
display: none;
:host {
--spectrum-overlay-animation-distance: 6px;
--spectrum-overlay-animation-duration: var(
--spectrum-animation-duration-100
);

opacity: 0;
pointer-events: none;
transition: transform var(--spectrum-overlay-animation-duration) ease-in-out,
opacity var(--spectrum-overlay-animation-duration) ease-in-out,
visibility 0s linear var(--spectrum-overlay-animation-duration);
visibility: hidden;
}

:host([open]) {
opacity: 1;
pointer-events: auto;
transition-delay: 0s;
visibility: visible;
}
75 changes: 75 additions & 0 deletions packages/toast/stories/toast.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { html, TemplateResult } from '@spectrum-web-components/base';
import '@spectrum-web-components/toast/sp-toast.js';
import '@spectrum-web-components/button/sp-button.js';

import { Placement } from '@spectrum-web-components/overlay';
import '@spectrum-web-components/overlay/overlay-trigger.js';
import { ifDefined } from '@spectrum-web-components/base/src/directives.js';

const toast = ({
variant = '',
open = true,
Expand Down Expand Up @@ -104,3 +108,74 @@ export const Negative = (args: Properties): TemplateResult =>

export const Info = (args: Properties): TemplateResult =>
variantDemo({ ...args, variant: 'info' });

const overlayStyles = html`
<style>
html,
body,
#root,
#root-inner,
sp-story-decorator {
height: 100%;
margin: 0;
}

sp-story-decorator > div {
display: contents;
}

sp-story-decorator::part(container) {
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
align-items: center;
justify-content: center;
}

overlay-trigger {
flex: none;
margin: 24px 0;
}

.self-managed:nth-child(3) {
margin-left: 50px;
}
</style>
`;

const overlaid = (openPlacement: Placement): TemplateResult => {
return html`
${overlayStyles}
${(
[
['bottom', ''],
['left', 'negative'],
['right', 'positive'],
['top', 'info'],
] as [Placement, string][]
).map(([placement, variant]) => {
return html`
<overlay-trigger
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should not insinuate that Toast elements can/should be opened on hover. I think if this was set up at type="click" and the slot was slot="click-content" that we'd be pretty good to go here!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha yes good point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in 592bdbd

placement=${placement}
open=${ifDefined(
openPlacement === placement ? 'click' : undefined
)}
>
<sp-button label="${placement} test" slot="trigger">
Click for ${variant ? variant : 'toast'} on the
${placement}
</sp-button>
<sp-toast slot="click-content" variant=${variant}>
${placement}
</sp-toast>
</overlay-trigger>
`;
})}
`;
};

export const overlaidTop = (): TemplateResult => overlaid('top');
export const overlaidRight = (): TemplateResult => overlaid('right');
export const overlaidBottom = (): TemplateResult => overlaid('bottom');
export const overlaidLeft = (): TemplateResult => overlaid('left');