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(split-button): fix width layout #8133

Merged
merged 5 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { newE2EPage } from "@stencil/core/testing";
import { html } from "../../../support/formatting";
import { accessible, defaults, disabled, focusable, hidden, renders } from "../../tests/commonTests";
import { CSS } from "./resources";

describe("calcite-split-button", () => {
describe("defaults", () => {
Expand Down Expand Up @@ -212,24 +211,6 @@ describe("calcite-split-button", () => {
expect(dropdownButton).toEqualAttribute("split-child", "secondary");
});

it("adds the relevant CSS class based on the width attribute", async () => {
const page = await newE2EPage();
await page.setContent(`<calcite-split-button width="auto"></calcite-split-button>`);

const element = await page.find(`calcite-split-button`);
const container = await page.find(`calcite-split-button >>> .${CSS.widthAuto}`);
expect(container).not.toBeNull();
expect(container).toHaveClass(CSS.widthAuto);

element.setAttribute("width", "half");
await page.waitForChanges();
expect(container).toHaveClass(CSS.widthHalf);

element.setAttribute("width", "full");
await page.waitForChanges();
expect(container).toHaveClass(CSS.widthFull);
});

it("should support dropdown item keyboard navigation", async () => {
const page = await newE2EPage();
await page.setContent(`<calcite-split-button scale="s" primary-text="Button">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,36 @@
@apply inline-block;
}

:host {
.split-button__container {
@apply flex items-stretch;
> calcite-dropdown > calcite-button {
@apply h-full align-top;
}
}
:host([width="auto"]) {
@apply w-auto;
}

:host {
&:host([kind="brand"]) {
--calcite-split-button-background: theme("colors.brand");
--calcite-split-button-divider: theme("colors.background.foreground.1");
}
&:host([kind="danger"]) {
--calcite-split-button-background: theme("colors.danger");
--calcite-split-button-divider: theme("colors.background.foreground.1");
}
&:host([kind="neutral"]) {
--calcite-split-button-background: theme("colors.background.foreground.3");
--calcite-split-button-divider: theme("colors.color.1");
}
&:host([kind="inverse"]) {
--calcite-split-button-background: var(--calcite-ui-inverse);
--calcite-split-button-divider: theme("colors.background.foreground.1");
}
:host([width="half"]) {
@apply w-2/4;
}

:host([width="full"]) {
@apply w-full;
}

:host([kind="brand"]) {
--calcite-split-button-background: theme("colors.brand");
--calcite-split-button-divider: theme("colors.background.foreground.1");
}

:host([kind="danger"]) {
--calcite-split-button-background: theme("colors.danger");
--calcite-split-button-divider: theme("colors.background.foreground.1");
}

:host([kind="neutral"]) {
--calcite-split-button-background: theme("colors.background.foreground.3");
--calcite-split-button-divider: theme("colors.color.1");
}

:host([kind="inverse"]) {
--calcite-split-button-background: var(--calcite-ui-inverse);
--calcite-split-button-divider: theme("colors.background.foreground.1");
}

:host([appearance="transparent"]) {
Expand Down Expand Up @@ -74,16 +78,11 @@
}
}

.width-auto {
@apply w-auto;
}

.width-half {
@apply w-1/2;
}

.width-full {
@apply w-full;
.split-button__container {
@apply flex items-stretch;
> calcite-dropdown > calcite-button {
@apply h-full align-top;
}
}

.split-button__divider-container {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,41 @@ export const simple = (): string => html`
</div>
`;

export const allWidths_TestOnly = (): string => html`
<div style="width:70vw;">
<calcite-split-button primary-text="auto" width="auto">
<calcite-dropdown-group selection-mode="none" group-title="Veggies">
<calcite-dropdown-item>Pea</calcite-dropdown-item>
<calcite-dropdown-item>Parsnip</calcite-dropdown-item>
<calcite-dropdown-item>Radish</calcite-dropdown-item>
<calcite-dropdown-item>Tomato</calcite-dropdown-item>
<calcite-dropdown-item>Rutabaga</calcite-dropdown-item>
<calcite-dropdown-item>Bean</calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-split-button>
<calcite-split-button primary-text="half width" width="half">
<calcite-dropdown-group selection-mode="none" group-title="Veggies">
<calcite-dropdown-item>Pea</calcite-dropdown-item>
<calcite-dropdown-item>Parsnip</calcite-dropdown-item>
<calcite-dropdown-item>Radish</calcite-dropdown-item>
<calcite-dropdown-item>Tomato</calcite-dropdown-item>
<calcite-dropdown-item>Rutabaga</calcite-dropdown-item>
<calcite-dropdown-item>Bean</calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-split-button>
<calcite-split-button primary-text="full width" width="full">
<calcite-dropdown-group selection-mode="none" group-title="Veggies">
<calcite-dropdown-item>Pea</calcite-dropdown-item>
<calcite-dropdown-item>Parsnip</calcite-dropdown-item>
<calcite-dropdown-item>Radish</calcite-dropdown-item>
<calcite-dropdown-item>Tomato</calcite-dropdown-item>
<calcite-dropdown-item>Rutabaga</calcite-dropdown-item>
<calcite-dropdown-item>Bean</calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-split-button>
</div>
`;

export const iconEnd_TestOnly = (): string => html`
<div style="width:70vw;">
<calcite-split-button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,10 @@ export class SplitButton implements InteractiveComponent, LoadableComponent {
}

render(): VNode {
const widthClasses = {
[CSS.container]: true,
[CSS.widthAuto]: this.width === "auto",
[CSS.widthHalf]: this.width === "half",
[CSS.widthFull]: this.width === "full",
};
const buttonWidth = this.width === "auto" ? "auto" : "full";

return (
<div class={widthClasses}>
<div class={CSS.container}>
<calcite-button
appearance={this.appearance}
disabled={this.disabled}
Expand Down
Loading