Skip to content

Commit

Permalink
refactor(focusring): Simplify focus ring to just use host element
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 500837060
  • Loading branch information
dfreedm authored and copybara-github committed Jan 10, 2023
1 parent a539286 commit f3383cd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 25 deletions.
13 changes: 3 additions & 10 deletions focus/lib/_focus-ring.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
// SPDX-License-Identifier: Apache-2.0
//

// stylelint-disable selector-class-pattern --
// Selector '.md3-*' should only be used in this project.

@use 'sass:map';
@use '../../sass/theme';
@use '../../sass/shape';
Expand All @@ -32,13 +29,10 @@ $_custom-property-prefix: 'focus-ring';
--_#{$token}: #{$value};
}

pointer-events: none;
}

.md3-focus-ring {
display: none;
position: absolute;
box-sizing: border-box;
pointer-events: none;
border: var(--_width) solid var(--_color);
border-start-start-radius: var(--_shape-start-start);
border-start-end-radius: var(--_shape-start-end);
Expand All @@ -49,12 +43,11 @@ $_custom-property-prefix: 'focus-ring';
// and touch target.
$vertical-inset: calc(-1 * (var(--_offset-vertical) + var(--_width)));
$horizontal-inset: calc(-1 * (var(--_offset-horizontal) + var(--_width)));

inset: $vertical-inset $horizontal-inset;
}

.md3-focus-ring--visible {
display: block;
:host([visible]) {
display: flex;
}
}

Expand Down
16 changes: 2 additions & 14 deletions focus/lib/focus-ring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

import {html, LitElement, TemplateResult} from 'lit';
import {LitElement} from 'lit';
import {property} from 'lit/decorators.js';
import {ClassInfo, classMap} from 'lit/directives/class-map.js';

/**
* @summary An accessible, themable ring designed to be shown on
Expand All @@ -25,16 +24,5 @@ export class FocusRing extends LitElement {
/**
* Makes the focus ring visible.
*/
@property({type: Boolean}) visible = false;

protected override render(): TemplateResult {
return html`<span class="md3-focus-ring ${
classMap(this.getRenderClasses())}"></span>`;
}

protected getRenderClasses(): ClassInfo {
return {
'md3-focus-ring--visible': this.visible,
};
}
@property({type: Boolean, reflect: true}) visible = false;
}
1 change: 0 additions & 1 deletion radio/lib/_radio.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ $_md-sys-motion: tokens.md-sys-motion-values();

input,
md-ripple,
md-focus-ring,
.icon {
inset: 0;
margin: auto;
Expand Down

0 comments on commit f3383cd

Please sign in to comment.