Skip to content
This repository has been archived by the owner on Jun 29, 2023. It is now read-only.

Commit

Permalink
feat(block): prevent disabled block content from being tabbed into (#652
Browse files Browse the repository at this point in the history
)

BREAKING CHANGE: disabled blocks are no longer interactive
  • Loading branch information
jcfranco authored Dec 19, 2019
1 parent 173aa21 commit 6ef11c4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/components/calcite-block/calcite-block.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,23 @@ describe("calcite-block", () => {
block.setProperty("disabled", true);
await page.waitForChanges();

// `tabindex=-1` on host removes children from the tab order
expect(block.getAttribute("tabindex")).toBe("-1");

await content.click();
expect(clickSpy).toHaveReceivedEventTimes(1);

const header = await page.find(`calcite-block >>> .${CSS.headerContainer}`);
const toggleSpy = await block.spyOnEvent("calciteBlockToggle");

await header.click();
await header.click();
expect(toggleSpy).toHaveReceivedEventTimes(0);

block.setAttribute("disabled", false);
await page.waitForChanges();

expect(block.getAttribute("tabindex")).toBeNull();
});

it("has a loading state", async () => {
Expand Down
9 changes: 9 additions & 0 deletions src/components/calcite-block/calcite-block.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
@include borderShadow();
}

:host([disabled]) {
pointer-events: none;
user-select: none;

.header-container {
opacity: var(--calcite-app-disabled-opacity);
}
}

calcite-loader[inline] {
color: var(--calcite-app-foreground-subtle);
}
Expand Down
7 changes: 4 additions & 3 deletions src/components/calcite-block/calcite-block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ export class CalciteBlock {
const toggleLabel = open ? textCollapse : textExpand;
const content = loading ? (
<calcite-loader inline is-active></calcite-loader>
) : !disabled ? (
) : (
<slot name={SLOTS.control} />
) : null;
);

const hasIcon = el.querySelector(`[slot=${SLOTS.icon}]`);
const headerContent = (
<header class={CSS.header}>
Expand Down Expand Up @@ -185,7 +186,7 @@ export class CalciteBlock {
);

return (
<Host>
<Host tabIndex={disabled ? -1 : null}>
<article aria-expanded={collapsible ? open.toString() : null} aria-busy={loading}>
{headerNode}
<div class={CSS.content} hidden={!hasContent || !open}>
Expand Down
1 change: 1 addition & 0 deletions src/components/utils/CalciteScrim.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const scrimDivStyle = {
position: "absolute",
right: "0",
top: "0",
userSelect: "none",
zIndex: "2"
};

Expand Down

0 comments on commit 6ef11c4

Please sign in to comment.