Skip to content

Commit

Permalink
feat: add custom focus ring color (#2334)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gavinbarron authored May 26, 2023
1 parent 071f3d5 commit 9f8953a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ mgt-login .login-button {
border-radius: 4px;
}

&:focus {
outline: 0;
}

&:disabled {
opacity: 0.4;
pointer-events: none;
Expand All @@ -74,7 +70,7 @@ mgt-login .login-button {
}

&:focus-visible {
outline: auto;
outline-style: $focus-ring-style;
}
}

Expand Down
12 changes: 11 additions & 1 deletion packages/mgt-components/src/styles/shared-styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* -------------------------------------------------------------------------------------------
*/

$focus-ring-style: var(--focus-ring-style, auto);

:host([hidden]) {
display: none;
}
Expand All @@ -17,7 +19,15 @@
--theme-primary-color: #0078d7;
--theme-dark-color: #005a9e;
}

:focus-visible {
// ensure default is correctly set for Firefox
outline-color: var(--focus-ring-color, Highlight);
// ensure default is set for other browsers
outline-color: var(--focus-ring-color, -webkit-focus-ring-color);
// set the style of the focus ring
// this needs to be something other than auto in Firefox to use the custom color
outline-style: $focus-ring-style;
}
.ms-Icon {
display: inline-block;
font-family: 'FabricMDL2Icons';
Expand Down
8 changes: 6 additions & 2 deletions stories/samples/general.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ export const cache = () => html`
</script>
`;
export const theme = () => html`
<div class="mgt-light">
<div class="mgt-light root">
<header class="mgt-dark">
<p>I should be dark, regional class</p>
<mgt-teams-channel-picker></mgt-teams-channel-picker>
<mgt-people-picker></mgt-people-picker>
<div class="mgt-light">
<p>I should be light, second level regional class</p>
<mgt-teams-channel-picker></mgt-teams-channel-picker>
Expand All @@ -187,6 +187,10 @@ export const theme = () => html`
<mgt-teams-channel-picker class="mgt-foo"></mgt-teams-channel-picker>
</div>
<style>
.root {
--focus-ring-color: red;
--focus-ring-style: solid;
}
.custom1 {
--input-border: 2px solid teal;
--input-background-color: #33c2c2;
Expand Down

0 comments on commit 9f8953a

Please sign in to comment.