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

fix(dropdown-item): bumping the scale of icon to M when parent dropdown is scale L #6254

Merged
4 changes: 2 additions & 2 deletions src/components/dropdown-item/dropdown-item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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");
}
Expand Down
30 changes: 16 additions & 14 deletions src/components/dropdown-item/dropdown-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -128,34 +127,34 @@ export class DropdownItem implements LoadableComponent {
}

render(): VNode {
const scale = getElementProp(this.el, "scale", "m");
const scale = getElementProp(this.el, "scale", this.scale);
const iconStartEl = (
<calcite-icon
class="dropdown-item-icon-start"
class={CSS.iconStart}
flipRtl={this.iconFlipRtl === "start" || this.iconFlipRtl === "both"}
icon={this.iconStart}
scale="s"
scale={scale === "l" ? "m" : "s"}
/>
);
const contentNode = (
<span class="dropdown-item-content">
<span class={CSS.itemContent}>
<slot />
</span>
);
const iconEndEl = (
<calcite-icon
class="dropdown-item-icon-end"
class={CSS.iconEnd}
flipRtl={this.iconFlipRtl === "end" || this.iconFlipRtl === "both"}
icon={this.iconEnd}
scale="s"
scale={scale === "l" ? "m" : "s"}
/>
);

const slottedContent =
this.iconStart && this.iconEnd
? [iconStartEl, contentNode, iconEndEl]
: this.iconStart
? [iconStartEl, <slot />]
? [iconStartEl, contentNode]
: this.iconEnd
? [contentNode, iconEndEl]
: contentNode;
Expand All @@ -165,7 +164,7 @@ export class DropdownItem implements LoadableComponent {
) : (
<a
aria-label={this.label}
class="dropdown-link"
class={CSS.link}
href={this.href}
ref={(el) => (this.childLink = el)}
rel={this.rel}
Expand Down Expand Up @@ -202,9 +201,9 @@ export class DropdownItem implements LoadableComponent {
>
{this.selectionMode !== "none" ? (
<calcite-icon
class="dropdown-item-icon"
class={CSS.icon}
icon={this.selectionMode === "multiple" ? "check" : "bullet-point"}
scale="s"
scale={scale === "l" ? "m" : "s"}
/>
) : null}
{contentEl}
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/components/dropdown-item/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
};
2 changes: 1 addition & 1 deletion src/components/dropdown/dropdown.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () =>
Expand Down
10 changes: 10 additions & 0 deletions src/components/dropdown/dropdown.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,3 +480,13 @@ export const flipPlacements_TestOnly = (): string => html`
document.querySelector(".my-dropdown").flipPlacements = ["right"];
</script>
`;

export const mediumIconForLargeDropdownItem_TestOnly = (): string => html`
<calcite-dropdown scale="l" width="m" open>
<calcite-dropdown-group group-title="View">
<calcite-dropdown-item scale="l">Table</calcite-dropdown-item>
<calcite-dropdown-item icon-start="grid" scale="l">Grid</calcite-dropdown-item>
<calcite-dropdown-item icon-start="grid" icon-end="grid" scale="l">Grid</calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-dropdown>
`;