From 91a0610b889a1531bce6746718ab15883e2d3b80 Mon Sep 17 00:00:00 2001 From: Matt Driscoll Date: Wed, 2 Aug 2023 10:01:06 -0700 Subject: [PATCH] fix(panel): Remove double border styling when content isn't provided (#7368) **Related Issue:** #7423 ## Summary - Fixes display issue when no content is slotted within a panel but a footer or action-bar is displayed then a double border occurs. - Cleans up code to use `slotChangeHasAssignedElement` dom utility for slot changes - Fixes conditional element surrounding default slot. - Adds screenshot tests --- .../src/components/panel/panel.scss | 18 ++-- .../src/components/panel/panel.stories.ts | 37 ++++++++ .../src/components/panel/panel.tsx | 94 ++++++++----------- .../src/components/panel/resources.ts | 2 +- 4 files changed, 85 insertions(+), 66 deletions(-) diff --git a/packages/calcite-components/src/components/panel/panel.scss b/packages/calcite-components/src/components/panel/panel.scss index 2caf6130d11..e8958a2415d 100644 --- a/packages/calcite-components/src/components/panel/panel.scss +++ b/packages/calcite-components/src/components/panel/panel.scss @@ -29,9 +29,7 @@ } .header { - border-block-end: 1px solid; @apply bg-foreground-1 - border-b-color-3 w-full items-stretch justify-start @@ -40,9 +38,12 @@ } .action-bar-container { - border-block-end: 1px solid; @apply w-full - z-header border-b-color-3; + z-header; +} + +.bottom-separator { + border-block-end: 1px solid var(--calcite-ui-border-3); } .action-bar-container ::slotted(calcite-action-bar) { @@ -92,11 +93,7 @@ } .content-wrapper { - @apply overflow-auto; -} - -.content-height { - @apply h-full; + @apply overflow-auto h-full; } .content-container { @@ -109,15 +106,14 @@ } .footer { - border-block-start: 1px solid; @apply bg-foreground-1 - border-t-color-3 flex w-full justify-evenly; flex: 0 0 auto; padding: var(--calcite-panel-footer-padding); + border-block-start: 1px solid var(--calcite-ui-border-3); } .fab-container { diff --git a/packages/calcite-components/src/components/panel/panel.stories.ts b/packages/calcite-components/src/components/panel/panel.stories.ts index a10eb5997e1..8d8913220d3 100644 --- a/packages/calcite-components/src/components/panel/panel.stories.ts +++ b/packages/calcite-components/src/components/panel/panel.stories.ts @@ -218,3 +218,40 @@ export const actionBarBackgroundColor_TestOnly = (): string => html`Hello world!

Slotted content!

`; + +export const footerWithoutContent_TestOnly = (): string => html` +

Footer content!

+
`; + +export const actionBarWithoutContent_TestOnly = (): string => html` + + + + + + + +`; + +export const footerAndActionBarWithoutContent_TestOnly = (): string => html` + + + + + + + +

Footer content!

+
`; diff --git a/packages/calcite-components/src/components/panel/panel.tsx b/packages/calcite-components/src/components/panel/panel.tsx index 647550eaf43..02f74aaaead 100644 --- a/packages/calcite-components/src/components/panel/panel.tsx +++ b/packages/calcite-components/src/components/panel/panel.tsx @@ -11,7 +11,12 @@ import { VNode, Watch, } from "@stencil/core"; -import { focusFirstTabbable, slotChangeGetAssignedElements, toAriaBoolean } from "../../utils/dom"; +import { + focusFirstTabbable, + slotChangeGetAssignedElements, + slotChangeHasAssignedElement, + toAriaBoolean, +} from "../../utils/dom"; import { connectInteractive, disconnectInteractive, @@ -168,6 +173,8 @@ export class Panel resizeObserver = createObserver("resize", () => this.resizeHandler()); + @State() hasDefaultContent = false; + @State() hasStartActions = false; @State() hasEndActions = false; @@ -257,28 +264,20 @@ export class Panel this.calcitePanelScroll.emit(); }; - handleHeaderActionsStartSlotChange = (event: Event): void => { - const elements = (event.target as HTMLSlotElement).assignedElements({ - flatten: true, - }); + handleDefaultSlotChange = (event: Event): void => { + this.hasDefaultContent = slotChangeHasAssignedElement(event); + }; - this.hasStartActions = !!elements.length; + handleHeaderActionsStartSlotChange = (event: Event): void => { + this.hasStartActions = slotChangeHasAssignedElement(event); }; handleHeaderActionsEndSlotChange = (event: Event): void => { - const elements = (event.target as HTMLSlotElement).assignedElements({ - flatten: true, - }); - - this.hasEndActions = !!elements.length; + this.hasEndActions = slotChangeHasAssignedElement(event); }; handleHeaderMenuActionsSlotChange = (event: Event): void => { - const elements = (event.target as HTMLSlotElement).assignedElements({ - flatten: true, - }); - - this.hasMenuItems = !!elements.length; + this.hasMenuItems = slotChangeHasAssignedElement(event); }; handleActionBarSlotChange = (event: Event): void => { @@ -292,35 +291,19 @@ export class Panel }; handleHeaderContentSlotChange = (event: Event): void => { - const elements = (event.target as HTMLSlotElement).assignedElements({ - flatten: true, - }); - - this.hasHeaderContent = !!elements.length; + this.hasHeaderContent = slotChangeHasAssignedElement(event); }; handleFooterSlotChange = (event: Event): void => { - const elements = (event.target as HTMLSlotElement).assignedElements({ - flatten: true, - }); - - this.hasFooterContent = !!elements.length; + this.hasFooterContent = slotChangeHasAssignedElement(event); }; handleFooterActionsSlotChange = (event: Event): void => { - const elements = (event.target as HTMLSlotElement).assignedElements({ - flatten: true, - }); - - this.hasFooterActions = !!elements.length; + this.hasFooterActions = slotChangeHasAssignedElement(event); }; handleFabSlotChange = (event: Event): void => { - const elements = (event.target as HTMLSlotElement).assignedElements({ - flatten: true, - }); - - this.hasFab = !!elements.length; + this.hasFab = slotChangeHasAssignedElement(event); }; // -------------------------------------------------------------------------- @@ -380,7 +363,10 @@ export class Panel renderActionBar(): VNode { return ( -