@@ -4,6 +4,10 @@ import {
44 makeMouseEvent ,
55 pressEnter ,
66 pressSpace ,
7+ down ,
8+ up ,
9+ keyDownOn ,
10+ keyUpOn ,
711} from '@polymer/iron-test-helpers/mock-interactions.js' ;
812
913import '../lion-button.js' ;
@@ -57,6 +61,53 @@ describe('lion-button', () => {
5761 expect ( el . hasAttribute ( 'disabled' ) ) . to . equal ( true ) ;
5862 } ) ;
5963
64+ describe ( 'active' , ( ) => {
65+ it ( 'updates "active" attribute on host when mousedown/mouseup on button' , async ( ) => {
66+ const el = await fixture ( `<lion-button>foo</lion-button>` ) ;
67+ const topEl = getTopElement ( el ) ;
68+
69+ down ( topEl ) ;
70+ expect ( el . active ) . to . be . true ;
71+ await el . updateComplete ;
72+ expect ( el . hasAttribute ( 'active' ) ) . to . be . true ;
73+
74+ up ( topEl ) ;
75+ expect ( el . active ) . to . be . false ;
76+ await el . updateComplete ;
77+ expect ( el . hasAttribute ( 'active' ) ) . to . be . false ;
78+ } ) ;
79+
80+ it ( 'updates "active" attribute on host when space keydown/keyup on button' , async ( ) => {
81+ const el = await fixture ( `<lion-button>foo</lion-button>` ) ;
82+ const topEl = getTopElement ( el ) ;
83+
84+ keyDownOn ( topEl , 32 ) ;
85+ expect ( el . active ) . to . be . true ;
86+ await el . updateComplete ;
87+ expect ( el . hasAttribute ( 'active' ) ) . to . be . true ;
88+
89+ keyUpOn ( topEl , 32 ) ;
90+ expect ( el . active ) . to . be . false ;
91+ await el . updateComplete ;
92+ expect ( el . hasAttribute ( 'active' ) ) . to . be . false ;
93+ } ) ;
94+
95+ it ( 'updates "active" attribute on host when enter keydown/keyup on button' , async ( ) => {
96+ const el = await fixture ( `<lion-button>foo</lion-button>` ) ;
97+ const topEl = getTopElement ( el ) ;
98+
99+ keyDownOn ( topEl , 13 ) ;
100+ expect ( el . active ) . to . be . true ;
101+ await el . updateComplete ;
102+ expect ( el . hasAttribute ( 'active' ) ) . to . be . true ;
103+
104+ keyUpOn ( topEl , 13 ) ;
105+ expect ( el . active ) . to . be . false ;
106+ await el . updateComplete ;
107+ expect ( el . hasAttribute ( 'active' ) ) . to . be . false ;
108+ } ) ;
109+ } ) ;
110+
60111 describe ( 'a11y' , ( ) => {
61112 it ( 'has a role="button" by default' , async ( ) => {
62113 const el = await fixture ( `<lion-button>foo</lion-button>` ) ;
0 commit comments