Skip to content

Commit

Permalink
feat(action-menu): support action-groups (#8273)
Browse files Browse the repository at this point in the history
**Related Issue:** #8202

## Summary

- Adds support for `calcite-action-group` within `calcite-action-menu`
- Adds screenshot test
- Adds e2e test
  • Loading branch information
driskull committed Nov 28, 2023
1 parent 5813985 commit c07144f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
flex-col;
}

.menu ::slotted(calcite-action) {
@apply focus-base
m-0.5
flex;
::slotted(calcite-action-group) {
border-block-end: 1px solid var(--calcite-ui-border-3);
}

.menu ::slotted(calcite-action[data-active]) {
@apply focus-outset;
outline-offset: 0px;
::slotted(calcite-action-group:last-child) {
border-block-end: 0;
}

.default-trigger {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ export const open = (): string =>
</calcite-action-menu>
`;

export const openWithGroups = (): string =>
html`
<calcite-action-menu open>
<calcite-action slot="trigger" text="Add" icon="banana"></calcite-action>
<calcite-action-group>
<calcite-action text="Plus" icon="plus" text-enabled></calcite-action
><calcite-action text="Minus" icon="minus" text-enabled></calcite-action>
</calcite-action-group>
<calcite-action-group>
<calcite-action text="Table" icon="table" text-enabled></calcite-action
></calcite-action-group>
<calcite-action-group>
<calcite-action text="Save" icon="save" text-enabled></calcite-action>
</calcite-action-group>
</calcite-action-menu>
`;

export const keyDownOpen_TestOnly = (): string =>
html`
<calcite-action-menu>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,23 @@ export class ActionMenu implements LoadableComponent {
.assignedElements({
flatten: true,
})
.filter((el) => el?.matches("calcite-action")) as HTMLCalciteActionElement[];
.reduce(
(previousValue: HTMLCalciteActionElement[], currentValue): HTMLCalciteActionElement[] => {
if (currentValue?.matches("calcite-action")) {
previousValue.push(currentValue as HTMLCalciteActionElement);
return previousValue;
}

if (currentValue?.matches("calcite-action-group")) {
return previousValue.concat(
Array.from(currentValue.querySelectorAll("calcite-action"))
);
}

return previousValue;
},
[]
);

this.actionElements = actions;
};
Expand Down
4 changes: 4 additions & 0 deletions packages/calcite-components/src/components/action/action.scss
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@
}
}

:host([data-active]) .button {
@apply focus-inset;
}

:host([scale="s"]) {
.button {
@apply text-n2h px-2 py-1 font-normal;
Expand Down

0 comments on commit c07144f

Please sign in to comment.