Skip to content

Commit 217324f

Browse files
authored
fix(switch): Fix for focus outline style in certain cases (#7414)
**Related Issue:** #7402 ## Summary Fix for focus issue where container was getting the focus outline. With this change, the component is still taking up 100% width of the Label, but the focus outline is limited to the visual area. We could look at adjusting the click area in a separate update if needed. Before: <img width="427" alt="Screenshot 2023-08-01 at 11 54 31 AM" src="https://github.com/Esri/calcite-design-system/assets/4733155/5641e388-d74d-4709-80fd-4c560916edda"> After: <img width="427" alt="Screenshot 2023-08-01 at 11 54 11 AM" src="https://github.com/Esri/calcite-design-system/assets/4733155/9b9b36d8-4ec3-484a-b5bd-497585471753">
1 parent 5f70bfe commit 217324f

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

packages/calcite-components/src/components/switch/switch.scss

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,8 @@
4747

4848
@include disabled();
4949

50-
// focus styles
51-
:host {
52-
@apply focus-base w-auto;
53-
}
54-
5550
.container {
56-
@apply rounded-full;
51+
@apply outline-0;
5752
}
5853

5954
.track {
@@ -67,9 +62,11 @@
6762
border
6863
border-solid
6964
align-top
70-
transition-all
71-
duration-150
72-
ease-in-out;
65+
focus-base;
66+
}
67+
68+
:host(:focus) .track {
69+
@apply focus-outset;
7370
}
7471

7572
.handle {
@@ -124,9 +121,5 @@
124121
}
125122
}
126123

127-
.container:focus {
128-
@apply focus-outset;
129-
}
130-
131124
@include hidden-form-input();
132125
@include base-component();

packages/calcite-components/src/components/switch/switch.stories.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const disabled_TestOnly = (): string => html`<calcite-switch disabled che
3939
export const Focus_TestOnly = (): string =>
4040
html`
4141
<div style="width:300px;height:300px; padding: 20px">
42-
<calcite-switch> </calcite-switch>
42+
<calcite-switch></calcite-switch>
4343
</div>
4444
<script>
4545
(async () => {
@@ -52,3 +52,20 @@ export const Focus_TestOnly = (): string =>
5252
Focus_TestOnly.parameters = {
5353
chromatic: { delay: 1000 },
5454
};
55+
56+
export const FocusLabel_TestOnly = (): string =>
57+
html`
58+
<div style="width:300px;height:300px; padding: 20px">
59+
<calcite-label>Switch label<calcite-switch></calcite-switch></calcite-label>
60+
</div>
61+
<script>
62+
(async () => {
63+
await customElements.whenDefined("calcite-switch");
64+
await document.querySelector("calcite-switch").setFocus();
65+
})();
66+
</script>
67+
`;
68+
69+
FocusLabel_TestOnly.parameters = {
70+
chromatic: { delay: 1000 },
71+
};

0 commit comments

Comments
 (0)