44 * SPDX-License-Identifier: Apache-2.0
55 */
66
7+ import '../../focus/focus-ring.js' ;
78import '../../ripple/ripple.js' ;
89
910import { html , TemplateResult } from 'lit' ;
10- import { property , query } from 'lit/decorators.js' ;
11+ import { property , query , state } from 'lit/decorators.js' ;
1112import { ClassInfo , classMap } from 'lit/directives/class-map.js' ;
1213
1314import { ActionElement , BeginPressConfig , EndPressConfig } from '../../action-element/action-element.js' ;
15+ import { pointerPress , shouldShowStrongFocus } from '../../focus/strong-focus.js' ;
1416import { MdRipple } from '../../ripple/ripple.js' ;
1517
1618/**
@@ -32,6 +34,8 @@ export class FabShared extends ActionElement {
3234
3335 @query ( 'md-ripple' ) ripple ! : MdRipple ;
3436
37+ @state ( ) protected showFocusRing = false ;
38+
3539 /**
3640 * @soyTemplate
3741 * @soyClasses fabClasses: .md3-fab
@@ -44,19 +48,24 @@ export class FabShared extends ActionElement {
4448 class ="md3-fab md3-surface ${ classMap ( this . getRenderClasses ( ) ) } "
4549 ?disabled ="${ this . disabled } "
4650 aria-label ="${ ariaLabel } "
51+ @focus ="${ this . handleFocus } "
52+ @blur ="${ this . handleBlur } "
4753 @pointerdown ="${ this . handlePointerDown } "
4854 @pointerup ="${ this . handlePointerUp } "
4955 @pointercancel ="${ this . handlePointerCancel } "
5056 @pointerleave ="${ this . handlePointerLeave } "
5157 @pointerenter ="${ this . handlePointerEnter } "
5258 @click ="${ this . handleClick } "
5359 @clickmod ="${ this . handleClick } "
54- @contextmenu ="${ this . handleContextMenu } "
55- > ${ this . renderElevationOverlay ( ) } ${ this . renderRipple ( ) }
60+ @contextmenu ="${ this . handleContextMenu } ">
61+ ${ this . renderElevationOverlay ( ) }
62+ ${ this . renderFocusRing ( ) }
63+ ${ this . renderRipple ( ) }
5664 < span class ="material-icons md3-fab__icon ">
5765 < slot name ="icon "> ${ this . icon } </ slot >
5866 </ span >
59- ${ this . renderLabel ( ) } ${ this . renderTouchTarget ( ) }
67+ ${ this . renderLabel ( ) }
68+ ${ this . renderTouchTarget ( ) }
6069 </ button > ` ;
6170 }
6271
@@ -93,6 +102,12 @@ export class FabShared extends ActionElement {
93102 this . disabled } "> </ md-ripple > `;
94103 }
95104
105+ /** @soyTemplate */
106+ protected renderFocusRing ( ) : TemplateResult {
107+ return html `< md-focus-ring .visible ="${
108+ this . showFocusRing } "> </ md-focus-ring > `;
109+ }
110+
96111 override beginPress ( { positionEvent} : BeginPressConfig ) {
97112 this . ripple . beginPress ( positionEvent ) ;
98113 }
@@ -104,10 +119,8 @@ export class FabShared extends ActionElement {
104119
105120 override handlePointerDown ( e : PointerEvent ) {
106121 super . handlePointerDown ( e ) ;
107- }
108-
109- override handlePointerUp ( e : PointerEvent ) {
110- super . handlePointerUp ( e ) ;
122+ pointerPress ( ) ;
123+ this . showFocusRing = shouldShowStrongFocus ( ) ;
111124 }
112125
113126 protected handlePointerEnter ( e : PointerEvent ) {
@@ -118,4 +131,12 @@ export class FabShared extends ActionElement {
118131 super . handlePointerLeave ( e ) ;
119132 this . ripple . endHover ( ) ;
120133 }
134+
135+ protected handleFocus ( ) {
136+ this . showFocusRing = shouldShowStrongFocus ( ) ;
137+ }
138+
139+ protected handleBlur ( ) {
140+ this . showFocusRing = false ;
141+ }
121142}
0 commit comments