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

feat(split-button): add placement and flipPlacements property #9548

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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,6 +1,6 @@
import { newE2EPage } from "@stencil/core/testing";
import { html } from "../../../support/formatting";
import { accessible, defaults, disabled, focusable, hidden, renders } from "../../tests/commonTests";
import { accessible, defaults, disabled, focusable, hidden, reflects, renders } from "../../tests/commonTests";

describe("calcite-split-button", () => {
describe("defaults", () => {
Expand All @@ -9,6 +9,23 @@ describe("calcite-split-button", () => {
propertyName: "overlayPositioning",
defaultValue: "absolute",
},
{
propertyName: "flipPlacements",
defaultValue: undefined,
},
{
propertyName: "placement",
defaultValue: "bottom-end",
},
]);
});

describe("reflects", () => {
reflects("calcite-split-button", [
{
propertyName: "placement",
value: "bottom-end",
},
]);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { iconNames } from "../../../.storybook/helpers";
import { boolean, modesDarkDefault } from "../../../.storybook/utils";
import { html } from "../../../support/formatting";
import { ATTRIBUTES } from "../../../.storybook/resources";
import { menuPlacements } from "../../utils/floating-ui";
import { SplitButton } from "./split-button";
const { appearance, kind, scale, width, iconType } = ATTRIBUTES;

Expand All @@ -13,6 +14,7 @@ type SplitButtonStoryArgs = Pick<
| "width"
| "loading"
| "disabled"
| "placement"
| "primaryIconStart"
| "primaryText"
| "primaryLabel"
Expand All @@ -29,6 +31,7 @@ export default {
width: width.defaultValue,
loading: false,
disabled: false,
placement: "bottom-end",
primaryIconStart: iconNames[0],
primaryText: "Primary Option",
primaryLabel: "Primary Option",
Expand All @@ -52,6 +55,10 @@ export default {
options: width.values,
control: { type: "select" },
},
placement: {
options: menuPlacements,
control: { type: "select" },
},
primaryIconStart: {
options: iconNames,
control: { type: "select" },
Expand All @@ -73,6 +80,7 @@ export const simple = (args: SplitButtonStoryArgs): string => html`
width="${args.width}"
${boolean("loading", args.loading)}
${boolean("disabled", args.disabled)}
placement="${args.placement}"
primary-icon-start="${args.primaryIconStart}"
primary-text="${args.primaryText}"
primary-label="${args.primaryLabel}"
Expand Down Expand Up @@ -168,6 +176,31 @@ export const iconStartAndIconEnd = (): string => html`
</div>
`;

export const placementTopStart = (): string => html`
Copy link
Member

Choose a reason for hiding this comment

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

Do you think we could replace this and similar tests by enhancing the [floatingUI common test helper](https://github.com/Esri/calcite-design-system/blob/main/packages/calcite-components/src/tests/commonTests/floatingUI.ts? If so, we can create a separate issue for this.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah that makes sense as a separate issue. Can you create one?

<div style="width:70vw;">
<calcite-split-button
active
appearance="solid"
kind="brand"
scale="m"
width="auto"
placement="top-start"
primary-icon-start="${iconNames[0]}"
primary-icon-end="${iconNames[0]}"
primary-text="Primary Option"
primary-label="Primary Option"
dropdown-label="Additional Options"
dropdown-icon-type="chevron"
>
<calcite-dropdown-group selection-mode="none">
<calcite-dropdown-item>Option 2</calcite-dropdown-item>
<calcite-dropdown-item>Option 3</calcite-dropdown-item>
<calcite-dropdown-item>Option 4</calcite-dropdown-item>
</calcite-dropdown-group>
</calcite-split-button>
</div>
`;

export const darkModeRTL_TestOnly = (): string => html`
<div style="width:70vw;">
<calcite-split-button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
VNode,
Watch,
} from "@stencil/core";
import { OverlayPositioning } from "../../utils/floating-ui";
import { FlipPlacement, MenuPlacement, OverlayPositioning } from "../../utils/floating-ui";
import {
connectInteractive,
disconnectInteractive,
Expand Down Expand Up @@ -84,6 +84,11 @@ export class SplitButton implements InteractiveComponent, LoadableComponent {
/** Accessible name for the dropdown menu. */
@Prop({ reflect: true }) dropdownLabel: string;

/**
* Defines the available placements that can be used when a flip occurs.
*/
@Prop() flipPlacements: FlipPlacement[];

/**
When `true`, a busy indicator is displayed on the primary button.
*/
Expand All @@ -99,6 +104,13 @@ export class SplitButton implements InteractiveComponent, LoadableComponent {
*/
@Prop({ reflect: true }) overlayPositioning: OverlayPositioning = "absolute";

/**
* Determines where the component will be positioned relative to the container element.
*
* @default "bottom-end"
*/
@Prop({ reflect: true }) placement: MenuPlacement = "bottom-end";

/** Specifies an icon to display at the end of the primary button. */
@Prop({ reflect: true }) primaryIconEnd: string;

Expand Down Expand Up @@ -207,10 +219,11 @@ export class SplitButton implements InteractiveComponent, LoadableComponent {
</div>
<calcite-dropdown
disabled={this.disabled}
flipPlacements={this.flipPlacements}
onClick={this.calciteSplitButtonSecondaryClickHandler}
open={this.active}
overlayPositioning={this.overlayPositioning}
placement="bottom-end"
placement={this.placement}
scale={this.scale}
width-scale={this.scale}
>
Expand Down
Loading