Skip to content

Commit

Permalink
fix: fixed banners next to drawers were positioned wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
hperrin committed Apr 13, 2021
1 parent 417b864 commit 5143e11
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
22 changes: 17 additions & 5 deletions packages/banner/Banner.svelte
Expand Up @@ -22,7 +22,7 @@
instance && instance.handleSecondaryActionClick()}
{...exclude($$restProps, ['content$', 'textWrapper$', 'graphic$'])}
>
<Fixed bind:fixed>
<Fixed bind:fixed {width}>
<div
bind:this={content}
class={classMap({
Expand Down Expand Up @@ -106,6 +106,7 @@
let content;
let addLayoutListener = getContext('SMUI:addLayoutListener');
let removeLayoutListener;
let width;
setContext('SMUI:label:context', 'banner');
setContext('SMUI:icon:context', 'banner');
Expand Down Expand Up @@ -133,9 +134,12 @@
instance = new MDCBannerFoundation({
addClass,
getContentHeight: () => {
element.classList.add('smui-banner--force-show');
const offsetHeight = content.offsetHeight;
element.classList.remove('smui-banner--force-show');
let offsetHeight = content.offsetHeight;
if (offsetHeight === 0) {
getElement().classList.add('smui-banner--force-show');
offsetHeight = content.offsetHeight;
getElement().classList.remove('smui-banner--force-show');
}
return offsetHeight;
},
notifyClosed: (reason) => {
Expand All @@ -157,7 +161,7 @@
});
instance.init();
instance.layout();
layout();
return () => {
instance.destroy();
Expand Down Expand Up @@ -202,6 +206,14 @@
}
export function layout() {
if (fixed) {
width = element.offsetWidth;
if (width === 0) {
element.classList.add('smui-banner--force-show');
width = element.offsetWidth;
element.classList.remove('smui-banner--force-show');
}
}
instance.layout();
}
Expand Down
8 changes: 7 additions & 1 deletion packages/banner/Fixed.svelte
@@ -1,5 +1,10 @@
{#if fixed}
<div bind:this={element} use:forwardEvents class="mdc-banner__fixed">
<div
bind:this={element}
use:forwardEvents
class="mdc-banner__fixed"
style={width == null ? null : `width: ${width}px;`}
>
<slot />
</div>
{:else}
Expand All @@ -13,6 +18,7 @@
const forwardEvents = forwardEventsBuilder(get_current_component());
export let fixed = false;
export let width = null;
let element;
Expand Down
1 change: 1 addition & 0 deletions site/src/routes/_app.scss
Expand Up @@ -75,6 +75,7 @@ body,
overflow: auto;
display: flex;
flex-direction: column;
position: relative;
}

.demo-main-content section {
Expand Down
8 changes: 1 addition & 7 deletions site/src/routes/demo/banner/Fixed.svelte
@@ -1,10 +1,4 @@
<Banner
open
fixed
mobileStacked
content$style="max-width: 100%;"
textWrapper$style="width: max-content;"
>
<Banner open fixed mobileStacked content$style="max-width: max-content;">
<Label slot="label">
This is a fixed banner! It's here to let you know an important thing. Once
you've successfully known the thing, you can dismiss it.
Expand Down

0 comments on commit 5143e11

Please sign in to comment.