From f8a1b327bbaf323074c890156d0885fe6f1e8d3c Mon Sep 17 00:00:00 2001 From: Arthur Moura Carvalho Date: Thu, 21 Nov 2019 05:47:31 -0300 Subject: [PATCH] feat(accordion): toggle via keyboard (#2085) --- e2e/accordion.e2e-spec.ts | 23 ++++++++++++++++++- .../accordion-item-header.component.ts | 2 ++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/e2e/accordion.e2e-spec.ts b/e2e/accordion.e2e-spec.ts index 2e4aa248d8..fec7c7be9b 100644 --- a/e2e/accordion.e2e-spec.ts +++ b/e2e/accordion.e2e-spec.ts @@ -4,7 +4,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. */ -import { browser, element, by } from 'protractor'; +import { browser, element, by, Key } from 'protractor'; import { hasClass } from './e2e-helper'; @@ -42,4 +42,25 @@ describe('accordion', () => { hasClass(element(by.css('nb-accordion > nb-accordion-item:nth-child(3)')), 'expanded'), ).toBeTruthy('second is expanded'); }); + + describe('a11y', () => { + + it('should be interactable through keyboard', () => { + expect( + hasClass( + element(by.css('nb-accordion > nb-accordion-item:nth-child(3)')) , 'expanded', + ), + ).toBeTruthy(); + + return element(by.css('nb-accordion > nb-accordion-item:nth-child(3) > nb-accordion-item-header')) + .sendKeys(Key.ENTER) + .then(() => { + expect( + hasClass( + element(by.css('nb-accordion > nb-accordion-item:nth-child(3)')), 'collapsed', + ), + ).toBeTruthy('nb-accordion-item is collapsed'); + }) + }) + }) }); diff --git a/src/framework/theme/components/accordion/accordion-item-header.component.ts b/src/framework/theme/components/accordion/accordion-item-header.component.ts index f44e434c78..7401107933 100644 --- a/src/framework/theme/components/accordion/accordion-item-header.component.ts +++ b/src/framework/theme/components/accordion/accordion-item-header.component.ts @@ -75,6 +75,8 @@ export class NbAccordionItemHeaderComponent implements OnInit, OnDestroy { } @HostListener('click') + @HostListener('keydown.space') + @HostListener('keydown.enter') toggle() { this.accordionItem.toggle(); }