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(list-item): restore tabbability when an item's disabled prop is toggled #8042

Merged
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 @@ -313,7 +313,7 @@ export class ListItem
}

componentDidRender(): void {
updateHostInteraction(this, "managed");
updateHostInteraction(this);
}

disconnectedCallback(): void {
Expand Down
44 changes: 43 additions & 1 deletion packages/calcite-components/src/components/list/list.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { E2EPage, newE2EPage } from "@stencil/core/testing";
import { debounceTimeout } from "./resources";
import { CSS } from "../list-item/resources";
import { DEBOUNCE_TIMEOUT as FILTER_DEBOUNCE_TIMEOUT } from "../filter/resources";
import { GlobalTestProps, dragAndDrop, isElementFocused } from "../../tests/utils";
import { GlobalTestProps, dragAndDrop, isElementFocused, getFocusedElementProp } from "../../tests/utils";
import { DragDetail } from "../../utils/sortableComponent";

const placeholder = placeholderImage({
Expand Down Expand Up @@ -109,6 +109,48 @@ describe("calcite-list", () => {
</calcite-list>`,
{ focusTarget: "child" }
);

it("disabling and enabling an item restores actions from being tabbable", async () => {
const page = await newE2EPage();
await page.setContent(html`
<calcite-list selection-mode="multiple">
<calcite-list-item label="first">
<calcite-action id="action-1" icon="information" slot="actions-end"></calcite-action>
</calcite-list-item>
<calcite-list-item label="second">
<calcite-action id="action-2" icon="information" slot="actions-end"></calcite-action>
</calcite-list-item>
<calcite-list-item label="third">
<calcite-action id="action-3" icon="information" slot="actions-end"></calcite-action>
</calcite-list-item>
</calcite-list>
`);

const [firstItem, secondItem] = await page.findAll("calcite-list-item");

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

await page.keyboard.press("Tab");
await page.keyboard.press("Tab");
await page.keyboard.press("Tab");

expect(await getFocusedElementProp(page, "id")).toBe("action-3");

await secondItem.setProperty("disabled", true);
await page.waitForChanges();
await secondItem.setProperty("disabled", false);
await page.waitForChanges();

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

await page.keyboard.press("Tab");
await page.keyboard.press("Tab");
await page.keyboard.press("Tab");

expect(await getFocusedElementProp(page, "id")).toBe("action-3");
});
});

it("navigating items after filtering", async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/calcite-components/src/utils/interactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const captureOnlyOptions = { capture: true } as const;
* technically, users can override `tabindex` and restore keyboard navigation, but this will be considered user error
*
* @param component
* @param hostIsTabbable
* @param hostIsTabbable – when set to true or its predicate returns true, the host is tabbable and will be managed by the helper. Set to "managed" for cases where a component's parent determines which item is tabbable (i.e., sets `tabindex` to allow tabbing).
Copy link
Member

Choose a reason for hiding this comment

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

✍️ 📜 🏆

*/
export function updateHostInteraction(
component: InteractiveComponent,
Expand Down
Loading