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(action-menu): Filter hidden or disabled actions via keyboard. #8336

Merged
merged 5 commits into from
Dec 5, 2023
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
Expand Up @@ -252,6 +252,46 @@ describe("calcite-action-menu", () => {
expect(actions[2].getAttribute(activeAttr)).toBe(null);
});

it("should handle ArrowDown navigation with disabled/hidden items", async () => {
const page = await newE2EPage({
html: html`<calcite-action-menu>
<calcite-action hidden id="first" text="Add" icon="plus" text-enabled></calcite-action>
<calcite-action disabled id="second" text="Add" icon="minus" text-enabled></calcite-action>
<calcite-action id="third" text="Add" icon="banana" text-enabled></calcite-action>
<calcite-action id="fourth" text="Add" icon="banana" text-enabled></calcite-action>
</calcite-action-menu> `,
});

await page.waitForChanges();

const actionMenu = await page.find("calcite-action-menu");
const actions = await page.findAll("calcite-action");
const trigger = await page.find(`calcite-action-menu >>> .${CSS.defaultTrigger}`);

expect(await actionMenu.getProperty("open")).toBe(false);

await actionMenu.callMethod("setFocus");
await page.waitForChanges();

await page.keyboard.press("ArrowDown");
await page.waitForChanges();

expect(await trigger.getProperty("active")).toBe(true);
expect(await actionMenu.getProperty("open")).toBe(true);
expect(actions[0].getAttribute(activeAttr)).toBe(null);
expect(actions[1].getAttribute(activeAttr)).toBe(null);
expect(actions[2].getAttribute(activeAttr)).toBe("");
expect(actions[3].getAttribute(activeAttr)).toBe(null);

await page.keyboard.press("ArrowDown");
await page.waitForChanges();

expect(actions[0].getAttribute(activeAttr)).toBe(null);
expect(actions[1].getAttribute(activeAttr)).toBe(null);
expect(actions[2].getAttribute(activeAttr)).toBe(null);
expect(actions[3].getAttribute(activeAttr)).toBe("");
});

it("should handle ArrowUp navigation", async () => {
const page = await newE2EPage({
html: html`<calcite-action-menu>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ export class ActionMenu implements LoadableComponent {
[]
);

this.actionElements = actions;
this.actionElements = actions.filter((action) => !action.disabled && !action.hidden);
};

isValidKey(key: string, supportedKeys: string[]): boolean {
Expand Down
Loading