Skip to content

Commit 9f8953a

Browse files
authored
feat: add custom focus ring color (#2334)
adds the ability for developers to define the color used for the focus ring requires the developer to set the --focus-ring-style for application in Firefox uses the General > Theme story as a working example
1 parent 071f3d5 commit 9f8953a

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

packages/mgt-components/src/components/mgt-login/mgt-login.scss

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ mgt-login .login-button {
6060
border-radius: 4px;
6161
}
6262

63-
&:focus {
64-
outline: 0;
65-
}
66-
6763
&:disabled {
6864
opacity: 0.4;
6965
pointer-events: none;
@@ -74,7 +70,7 @@ mgt-login .login-button {
7470
}
7571

7672
&:focus-visible {
77-
outline: auto;
73+
outline-style: $focus-ring-style;
7874
}
7975
}
8076

packages/mgt-components/src/styles/shared-styles.scss

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* -------------------------------------------------------------------------------------------
66
*/
77

8+
$focus-ring-style: var(--focus-ring-style, auto);
9+
810
:host([hidden]) {
911
display: none;
1012
}
@@ -17,7 +19,15 @@
1719
--theme-primary-color: #0078d7;
1820
--theme-dark-color: #005a9e;
1921
}
20-
22+
:focus-visible {
23+
// ensure default is correctly set for Firefox
24+
outline-color: var(--focus-ring-color, Highlight);
25+
// ensure default is set for other browsers
26+
outline-color: var(--focus-ring-color, -webkit-focus-ring-color);
27+
// set the style of the focus ring
28+
// this needs to be something other than auto in Firefox to use the custom color
29+
outline-style: $focus-ring-style;
30+
}
2131
.ms-Icon {
2232
display: inline-block;
2333
font-family: 'FabricMDL2Icons';

stories/samples/general.stories.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ export const cache = () => html`
166166
</script>
167167
`;
168168
export const theme = () => html`
169-
<div class="mgt-light">
169+
<div class="mgt-light root">
170170
<header class="mgt-dark">
171171
<p>I should be dark, regional class</p>
172-
<mgt-teams-channel-picker></mgt-teams-channel-picker>
172+
<mgt-people-picker></mgt-people-picker>
173173
<div class="mgt-light">
174174
<p>I should be light, second level regional class</p>
175175
<mgt-teams-channel-picker></mgt-teams-channel-picker>
@@ -187,6 +187,10 @@ export const theme = () => html`
187187
<mgt-teams-channel-picker class="mgt-foo"></mgt-teams-channel-picker>
188188
</div>
189189
<style>
190+
.root {
191+
--focus-ring-color: red;
192+
--focus-ring-style: solid;
193+
}
190194
.custom1 {
191195
--input-border: 2px solid teal;
192196
--input-background-color: #33c2c2;

0 commit comments

Comments
 (0)