Skip to content

Commit

Permalink
fix(ld-sidenav): update stacking to top on component did load
Browse files Browse the repository at this point in the history
  • Loading branch information
borisdiakur committed Oct 11, 2022
1 parent bf5ff99 commit 2ca795f
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

transform: translateY(
var(
--ld-slider-navitem-move-up-closable,
var(--ld-slider-navitem-move-up, 0px)
--ld-sidenav-navitem-move-up-closable,
var(--ld-sidenav-navitem-move-up, 0px)
)
);
transition: var(--ld-sidenav-stack-to-top-transition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ export class LdSidenavAccordion {
handleSidenavBreakpointChange(ev: CustomEvent<boolean>) {
if (ev.target !== this.sidenav) return
this.sidenavClosable = ev.detail
if (this.sidenavClosable) {
toggleStackToTop(this.el, false)
} else {
toggleStackToTop(this.el, this.sidenav.narrow && this.sidenavCollapsed)
}
this.updateStackToTop()
}

@Listen('ldSidenavSliderChange', { target: 'window', passive: true })
Expand Down Expand Up @@ -96,7 +92,7 @@ export class LdSidenavAccordion {
// Collapse or expand accordion on sidenav collapse or expansion.
if (ev.target !== this.sidenav) return
this.sidenavCollapsed = ev.detail.collapsed
toggleStackToTop(this.el, this.sidenav.narrow && this.sidenavCollapsed)
this.updateStackToTop()
if (this.sidenavCollapsed) {
if (this.preserveState) {
this.expandOnSidenavExpansion = this.sectionRef.expanded
Expand All @@ -123,6 +119,14 @@ export class LdSidenavAccordion {
}
}

private updateStackToTop = () => {
if (this.sidenavClosable) {
toggleStackToTop(this.el, false)
} else {
toggleStackToTop(this.el, this.sidenav.narrow && this.sidenavCollapsed)
}
}

componentWillLoad() {
this.inAccordion = this.el.parentElement.tagName === 'LD-SIDENAV-ACCORDION'
this.rounded = !!this.el.querySelector(
Expand All @@ -132,6 +136,17 @@ export class LdSidenavAccordion {
'ld-sidenav-navitem[slot="toggle"][mode="secondary"],ld-sidenav-navitem[slot="toggle"][mode="tertiary"]'
)
this.sidenav = closest('ld-sidenav', this.el)
if (this.sidenav) {
this.sidenavCollapsed = this.sidenav.collapsed
}
}

componentDidLoad() {
// The ldSidenavCollapsedChange event can be fired before this component is loaded.
// So we need to update the stacking here.
setTimeout(() => {
this.updateStackToTop()
})
}

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,17 @@ export class LdSidenavHeader {
*/
@Method()
async updateCollapsible() {
this.sidenavCollapsible = this.sidenav.collapsible
if (this.sidenav) {
this.sidenavCollapsible = this.sidenav.collapsible
}
}

componentWillLoad() {
this.sidenav = this.el.closest('ld-sidenav')
if (this.sidenav) {
this.sidenavAlignement = this.sidenav.align
this.sidenavCollapsible = this.sidenav.collapsible
this.sidenavCollapsed = this.sidenav.collapsed
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
transition: var(--ld-sidenav-stack-to-top-transition);
transform: translateY(
var(
--ld-slider-navitem-move-up-closable,
var(--ld-slider-navitem-move-up, 0px)
--ld-sidenav-navitem-move-up-closable,
var(--ld-sidenav-navitem-move-up, 0px)
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,18 @@ export class LdSidenavNavitem implements InnerFocusable {
) {
if (ev.target !== this.sidenav) return
this.sidenavCollapsed = ev.detail.collapsed
toggleStackToTop(this.el, this.sidenav.narrow && this.sidenavCollapsed)
this.tooltipRef.hideTooltip()
this.updateStackToTop()
this.tooltipRef?.hideTooltip()
}

@Listen('ldSidenavBreakpointChange', { target: 'window', passive: true })
handleSidenavBreakpointChange(ev: CustomEvent<boolean>) {
if (ev.target !== this.sidenav) return
this.sidenavClosable = ev.detail
this.updateStackToTop()
}

private updateStackToTop = () => {
if (this.sidenavClosable) {
toggleStackToTop(this.el, false)
} else {
Expand Down Expand Up @@ -204,6 +208,7 @@ export class LdSidenavNavitem implements InnerFocusable {
this.sidenavAlignement = this.sidenav.align
this.sidenavExpandsOnMouseEnter =
this.sidenav.expandTrigger === 'mouseenter'
this.sidenavCollapsed = this.sidenav.collapsed
}
if (!['secondary', 'tertiary'].includes(this.mode)) {
this.tooltipContent = this.el.textContent.trim()
Expand All @@ -229,6 +234,12 @@ export class LdSidenavNavitem implements InnerFocusable {
setTimeout(() => {
this.slotContainerRef.style.alignItems = 'center'
}, 200)

// The ldSidenavCollapsedChange event can be fired before this component is loaded.
// So we need to update the stacking here.
setTimeout(() => {
this.updateStackToTop()
})
}

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
hr {
transform: translateY(
var(
--ld-slider-navitem-move-up-closable,
var(--ld-slider-navitem-move-up, 0px)
--ld-sidenav-navitem-move-up-closable,
var(--ld-sidenav-navitem-move-up, 0px)
)
);
transition: var(--ld-sidenav-stack-to-top-transition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ export class LdSidenavSeparator {
handleSidenavBreakpointChange(ev: CustomEvent<boolean>) {
if (ev.target !== this.sidenav) return
this.sidenavClosable = ev.detail
if (this.sidenavClosable) {
toggleStackToTop(this.el, false)
} else {
toggleStackToTop(this.el, this.sidenav.narrow && this.sidenavCollapsed)
}
this.updateStackToTop()
}

private computeScaleXCollapsed = () => {
Expand All @@ -72,13 +68,30 @@ export class LdSidenavSeparator {
return sidenavNavitemIconSize / (sidenavWidth - 2 * sidenavPaddingX)
}

private updateStackToTop = () => {
if (this.sidenavClosable) {
toggleStackToTop(this.el, false)
} else {
toggleStackToTop(this.el, this.sidenav.narrow && this.sidenavCollapsed)
}
}

componentWillLoad() {
this.sidenav = closest('ld-sidenav', this.el)
if (this.sidenav) {
this.scaleXCollapsed = this.computeScaleXCollapsed() || 1
this.sidenavCollapsed = this.sidenav.collapsed
}
}

componentDidLoad() {
// The ldSidenavCollapsedChange event can be fired before this component is loaded.
// So we need to update the stacking here.
setTimeout(() => {
this.updateStackToTop()
})
}

render() {
const cl = getClassNames([
'ld-sidenav-separator',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class LdSidenavToggleOutside implements InnerFocusable {
@State() sidenavClosable: boolean
@State() sidenavCollapsed: boolean
@State() sidenavCollapsedFully: boolean
@State() sidenavAlignement: 'left' | 'right' = 'left'
@State() sidenavAlignement: 'left' | 'right'

/** Sets focus on the radio button. */
@Method()
Expand Down Expand Up @@ -73,7 +73,7 @@ export class LdSidenavToggleOutside implements InnerFocusable {
`The ld-sidenav-toggle-outside component is expecting to have an ld-sidenav component as its next element sibling, but instead there was: ${this.sidenav}`
)
}
this.sidenavAlignement = this.sidenav.align
this.sidenavAlignement = this.sidenav.align || 'left'
}

render() {
Expand Down
2 changes: 1 addition & 1 deletion src/liquid/components/ld-sidenav/ld-sidenav.shadow.css
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
&(.ld-sidenav--closable) {
--ld-sidenav-collapse-content-transition: none;
--ld-sidenav-stack-to-top-transition: none;
--ld-slider-navitem-move-up-closable: 0;
--ld-sidenav-navitem-move-up-closable: 0;
--ld-sidenav-translate-x-delta: 0;
width: 100%;
transform: translateX(
Expand Down
Loading

1 comment on commit 2ca795f

@vercel
Copy link

@vercel vercel bot commented on 2ca795f Oct 11, 2022

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

liquid – ./

liquid-oxygen.vercel.app
liquid-git-main-uxsd.vercel.app
liquid-uxsd.vercel.app

Please sign in to comment.