From 8957e8d3aa22862ef4c1535d4928dc0ace965d9d Mon Sep 17 00:00:00 2001 From: Eliza Khachatryan Date: Sat, 14 Jan 2023 18:35:41 -0800 Subject: [PATCH] fix(dropdown-item): bumping the scale of icon to M when parent dropdown is scale L (#6254) **Related Issue:** #5698 ## Summary Bumping the scale of the icon to M when the parent `dropdown-item` is `scale="l"` for a visual distinction between larger and smaller components without affecting the height of the `dropdown-item` when icon(s) are added or removed. Added a `_testOnly` snapshot. --- .../dropdown-item/dropdown-item.scss | 4 +-- .../dropdown-item/dropdown-item.tsx | 30 ++++++++++--------- src/components/dropdown-item/resources.ts | 7 ++++- src/components/dropdown/dropdown.e2e.ts | 2 +- src/components/dropdown/dropdown.stories.ts | 10 +++++++ 5 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/components/dropdown-item/dropdown-item.scss b/src/components/dropdown-item/dropdown-item.scss index d86f5afd981..f4d2902df4b 100644 --- a/src/components/dropdown-item/dropdown-item.scss +++ b/src/components/dropdown-item/dropdown-item.scss @@ -11,7 +11,7 @@ } .container--l { - @apply text-0h py-3; + @apply text-0h py-2.5; padding-inline-end: theme("padding.4"); padding-inline-start: theme("padding.10"); } @@ -63,7 +63,7 @@ } .dropdown-item-content { - @apply flex-auto; + @apply flex-auto py-0.5; padding-inline-end: theme("margin.auto"); padding-inline-start: theme("margin.1"); } diff --git a/src/components/dropdown-item/dropdown-item.tsx b/src/components/dropdown-item/dropdown-item.tsx index c2dd8a58997..6ba35b1fd7f 100644 --- a/src/components/dropdown-item/dropdown-item.tsx +++ b/src/components/dropdown-item/dropdown-item.tsx @@ -12,16 +12,15 @@ import { } from "@stencil/core"; import { getElementProp, toAriaBoolean } from "../../utils/dom"; import { ItemKeyboardEvent } from "../dropdown/interfaces"; - +import { RequestedItem } from "../dropdown-group/interfaces"; +import { FlipContext, Scale, SelectionMode } from "../interfaces"; +import { CSS } from "./resources"; import { componentLoaded, LoadableComponent, setComponentLoaded, setUpLoadableComponent } from "../../utils/loadable"; -import { RequestedItem } from "../dropdown-group/interfaces"; -import { FlipContext, SelectionMode } from "../interfaces"; -import { CSS } from "./resources"; /** * @slot - A slot for adding text. @@ -128,26 +127,26 @@ export class DropdownItem implements LoadableComponent { } render(): VNode { - const scale = getElementProp(this.el, "scale", "m"); + const scale = getElementProp(this.el, "scale", this.scale); const iconStartEl = ( ); const contentNode = ( - + ); const iconEndEl = ( ); @@ -155,7 +154,7 @@ export class DropdownItem implements LoadableComponent { this.iconStart && this.iconEnd ? [iconStartEl, contentNode, iconEndEl] : this.iconStart - ? [iconStartEl, ] + ? [iconStartEl, contentNode] : this.iconEnd ? [contentNode, iconEndEl] : contentNode; @@ -165,7 +164,7 @@ export class DropdownItem implements LoadableComponent { ) : ( (this.childLink = el)} rel={this.rel} @@ -202,9 +201,9 @@ export class DropdownItem implements LoadableComponent { > {this.selectionMode !== "none" ? ( ) : null} {contentEl} @@ -284,6 +283,9 @@ export class DropdownItem implements LoadableComponent { /** if href is requested, track the rendered child link*/ private childLink: HTMLAnchorElement; + /** Specifies the scale of dropdown-item controlled by the parent, defaults to m */ + scale: Scale = "m"; + //-------------------------------------------------------------------------- // // Private Methods diff --git a/src/components/dropdown-item/resources.ts b/src/components/dropdown-item/resources.ts index f10e7ed8612..6a7d999ea86 100644 --- a/src/components/dropdown-item/resources.ts +++ b/src/components/dropdown-item/resources.ts @@ -5,5 +5,10 @@ export const CSS = { containerLarge: "container--l", containerMulti: "container--multi-selection", containerSingle: "container--single-selection", - containerNone: "container--none-selection" + containerNone: "container--none-selection", + icon: "dropdown-item-icon", + iconEnd: "dropdown-item-icon-end", + iconStart: "dropdown-item-icon-start", + itemContent: "dropdown-item-content", + link: "dropdown-link" }; diff --git a/src/components/dropdown/dropdown.e2e.ts b/src/components/dropdown/dropdown.e2e.ts index bdde9a6dab2..8781da42265 100644 --- a/src/components/dropdown/dropdown.e2e.ts +++ b/src/components/dropdown/dropdown.e2e.ts @@ -1069,7 +1069,7 @@ describe("calcite-dropdown", () => { filterInput.value = "nums"; }); - expect(dropdownContentHeight.height).toBe("64px"); + expect(dropdownContentHeight.height).toBe("72px"); }); it("owns a floating-ui", () => diff --git a/src/components/dropdown/dropdown.stories.ts b/src/components/dropdown/dropdown.stories.ts index 6f58e03cbd3..b650d85fc35 100644 --- a/src/components/dropdown/dropdown.stories.ts +++ b/src/components/dropdown/dropdown.stories.ts @@ -480,3 +480,13 @@ export const flipPlacements_TestOnly = (): string => html` document.querySelector(".my-dropdown").flipPlacements = ["right"]; `; + +export const mediumIconForLargeDropdownItem_TestOnly = (): string => html` + + + Table + Grid + Grid + + +`;