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

[core] fix(Toaster): use absolute positioning when inline #4555

Merged
merged 1 commit into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/core/src/components/toast/_toast.scss
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,19 @@ $toast-margin: $pt-grid-size * 2 !default;
// container will not block clicks on elements behind it
pointer-events: none;

position: fixed;
right: 0;

// #975 ensure toasts are on top of everything (esp dialogs)
z-index: $pt-z-index-overlay * 2;

&.#{ns}-toast-container-in-portal {
position: fixed;
}

&.#{$ns}-toast-container-inline {
position: absolute;
}

&.#{$ns}-toast-container-top {
top: 0;
}
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/components/toast/toaster.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ export class Toaster extends AbstractPureComponent2<IToasterProps, IToasterState
}

public render() {
// $pt-transition-duration * 3 + $pt-transition-duration / 2
const classes = classNames(Classes.TOAST_CONTAINER, this.getPositionClasses(), this.props.className);
return (
<Overlay
Expand All @@ -198,6 +197,7 @@ export class Toaster extends AbstractPureComponent2<IToasterProps, IToasterState
hasBackdrop={false}
isOpen={this.state.toasts.length > 0 || this.props.children != null}
onClose={this.handleClose}
// $pt-transition-duration * 3 + $pt-transition-duration / 2
transitionDuration={350}
transitionName={Classes.TOAST}
usePortal={this.props.usePortal}
Expand Down Expand Up @@ -238,7 +238,10 @@ export class Toaster extends AbstractPureComponent2<IToasterProps, IToasterState
private getPositionClasses() {
const positions = this.props.position!.split("-");
// NOTE that there is no -center class because that's the default style
return positions.map(p => `${Classes.TOAST_CONTAINER}-${p.toLowerCase()}`);
return [
...positions.map(p => `${Classes.TOAST_CONTAINER}-${p.toLowerCase()}`),
`${Classes.TOAST_CONTAINER}-${this.props.usePortal ? "in-portal" : "inline"}`,
];
}

private getDismissHandler = (toast: IToastOptions) => (timeoutExpired: boolean) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class ToastExample extends React.PureComponent<IExampleProps<IBlueprintEx
autoFocus: false,
canEscapeKeyClear: true,
position: Position.TOP,
usePortal: true,
};

private TOAST_BUILDERS: IToastDemo[] = [
Expand Down Expand Up @@ -123,6 +124,8 @@ export class ToastExample extends React.PureComponent<IExampleProps<IBlueprintEx

private toggleEscapeKey = handleBooleanChange(canEscapeKeyClear => this.setState({ canEscapeKeyClear }));

private toggleUsePortal = handleBooleanChange(usePortal => this.setState({ usePortal }));

public render() {
return (
<Example options={this.renderOptions()} {...this.props}>
Expand All @@ -134,7 +137,7 @@ export class ToastExample extends React.PureComponent<IExampleProps<IBlueprintEx
}

protected renderOptions() {
const { autoFocus, canEscapeKeyClear, position, maxToasts } = this.state;
const { autoFocus, canEscapeKeyClear, position, maxToasts, usePortal } = this.state;
return (
<>
<H5>Props</H5>
Expand All @@ -154,6 +157,7 @@ export class ToastExample extends React.PureComponent<IExampleProps<IBlueprintEx
</Label>
<Switch label="Auto focus" checked={autoFocus} onChange={this.toggleAutoFocus} />
<Switch label="Can escape key clear" checked={canEscapeKeyClear} onChange={this.toggleEscapeKey} />
<Switch label="Use portal" checked={usePortal} onChange={this.toggleUsePortal} />
</>
);
}
Expand Down
7 changes: 7 additions & 0 deletions packages/docs-app/src/styles/_examples.scss
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,13 @@
}
}

#{example("ToastExample")} {
.docs-example {
// necessary for inline Toaster (usePortal={false})
position: relative;
}
}

//
// DATETIME
//
Expand Down