Skip to content

Commit

Permalink
fix: Restore styled focus rings to drag and resize handles
Browse files Browse the repository at this point in the history
  • Loading branch information
avinashbot committed Oct 30, 2023
1 parent 19395ad commit 6431927
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 23 deletions.
25 changes: 2 additions & 23 deletions src/board-item/styles.scss
Original file line number Diff line number Diff line change
@@ -1,26 +1,5 @@
@use "../../node_modules/@cloudscape-design/design-tokens/index.scss" as cs;

@mixin focus-highlight($gutter: 4px, $border-radius: cs.$border-radius-control-default-focus-ring) {
position: relative;
box-sizing: border-box;
outline: none;
& {
outline: 2px dotted transparent;
outline-offset: calc($gutter - 1px);
}
&::before {
content: " ";
display: block;
position: absolute;
box-sizing: border-box;
left: calc(-1 * #{$gutter});
top: calc(-1 * #{$gutter});
width: calc(100% + 2 * #{$gutter});
height: calc(100% + 2 * #{$gutter});
border-radius: $border-radius;
border: 2px solid cs.$color-border-item-focused;
}
}
@use "../internal/shared.scss" as shared;

.root {
display: contents;
Expand All @@ -31,7 +10,7 @@
box-shadow: cs.$shadow-container-active;

:global([data-awsui-focus-visible]) & {
@include focus-highlight(0px, cs.$border-radius-container);
@include shared.focus-highlight(0px, cs.$border-radius-container);
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/internal/drag-handle/styles.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@use "../shared.scss" as shared;

.handle {
cursor: grab;
}
Expand All @@ -6,6 +8,10 @@
cursor: grabbing;
}

.handle:not(.active):focus-visible {
@include shared.focus-highlight();
}

.active {
outline: none;
}
6 changes: 6 additions & 0 deletions src/internal/resize-handle/styles.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
@use "../shared.scss" as shared;

.handle {
cursor: nwse-resize;
}

.handle:not(.active):focus-visible {
@include shared.focus-highlight();
}

.active {
outline: none;
}
23 changes: 23 additions & 0 deletions src/internal/shared.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@use "../../node_modules/@cloudscape-design/design-tokens/index.scss" as cs;

@mixin focus-highlight($gutter: 4px, $border-radius: cs.$border-radius-control-default-focus-ring) {
position: relative;
box-sizing: border-box;
outline: none;
& {
outline: 2px dotted transparent;
outline-offset: calc($gutter - 1px);
}
&::before {
content: " ";
display: block;
position: absolute;
box-sizing: border-box;
left: calc(-1 * #{$gutter});
top: calc(-1 * #{$gutter});
width: calc(100% + 2 * #{$gutter});
height: calc(100% + 2 * #{$gutter});
border-radius: $border-radius;
border: 2px solid cs.$color-border-item-focused;
}
}
16 changes: 16 additions & 0 deletions test/visual/drag-states.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ class DndPageObject extends ScreenshotPageObject {
}
}

test(
"renders correctly styled focus ring around the drag handle",
setupTest("/index.html#/dnd/engine-a2h-test", DndPageObject, async (page) => {
await page.focus(boardItemHandle("A"));
expect(await page.fullPageScreenshot()).toMatchImageSnapshot();
})
);

test(
"renders correctly styled focus ring around the resize handle",
setupTest("/index.html#/dnd/engine-a2h-test", DndPageObject, async (page) => {
await page.focus(boardItemResizeHandle("A"));
expect(await page.fullPageScreenshot()).toMatchImageSnapshot();
})
);

test(
"active item overlays other items",
setupTest("/index.html#/dnd/engine-a2h-test", DndPageObject, async (page) => {
Expand Down

0 comments on commit 6431927

Please sign in to comment.