@@ -87,6 +87,11 @@ export class LionButton extends DelegateMixin(SlotMixin(LionLitElement)) {
8787 fill : whitesmoke;
8888 }
8989
90+ : host (: active ) .btn ,
91+ .btn [active ] {
92+ background : grey;
93+ }
94+
9095 : host ([disabled ]) {
9196 pointer-events : none;
9297 }
@@ -140,32 +145,42 @@ export class LionButton extends DelegateMixin(SlotMixin(LionLitElement)) {
140145
141146 connectedCallback ( ) {
142147 super . connectedCallback ( ) ;
143- this . __setupKeydownDelegation ( ) ;
148+ this . __setupDelegation ( ) ;
144149 }
145150
146151 disconnectedCallback ( ) {
147152 super . disconnectedCallback ( ) ;
148- this . __teardownKeydownDelegation ( ) ;
153+ this . __teardownDelegation ( ) ;
149154 }
150155
151156 __clickDelegationHandler ( e ) {
152157 e . stopPropagation ( ) ; // prevent click on the fake element and cause click on the native button
153158 this . $$slot ( '_button' ) . click ( ) ;
154159 }
155160
156- __setupKeydownDelegation ( ) {
161+ __setupDelegation ( ) {
157162 this . addEventListener ( 'keydown' , this . __keydownDelegationHandler ) ;
163+ this . addEventListener ( 'keyup' , this . __keyupDelegationHandler ) ;
158164 }
159165
160- __teardownKeydownDelegation ( ) {
166+ __teardownDelegation ( ) {
161167 this . removeEventListener ( 'keydown' , this . __keydownDelegationHandler ) ;
168+ this . removeEventListener ( 'keyup' , this . __keyupDelegationHandler ) ;
162169 }
163170
164171 __keydownDelegationHandler ( e ) {
172+ if ( e . keyCode === 32 /* space */ || e . keyCode === 13 /* enter */ ) {
173+ e . preventDefault ( ) ;
174+ this . shadowRoot . querySelector ( '.btn' ) . setAttribute ( 'active' , '' ) ;
175+ }
176+ }
177+
178+ __keyupDelegationHandler ( e ) {
165179 // Makes the real button the trigger in forms (will submit form, as opposed to paper-button)
166180 // and make click handlers on button work on space and enter
167181 if ( e . keyCode === 32 /* space */ || e . keyCode === 13 /* enter */ ) {
168182 e . preventDefault ( ) ;
183+ this . shadowRoot . querySelector ( '.btn' ) . removeAttribute ( 'active' ) ;
169184 this . $$slot ( '_button' ) . click ( ) ;
170185 }
171186 }
0 commit comments