Skip to content

Commit 6dd154d

Browse files
authored
Added required aria-expanded attributes and fixed closing focus (#210)
1 parent e008174 commit 6dd154d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/components/popup.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
// (c) Mathigon
44
// =============================================================================
55

6-
76
import {$body, CustomElementView, ElementView, register} from '../';
87

9-
108
/**
119
* Popup component that reveals its `.popup-body` child when clicked.
1210
*/
1311
@register('x-popup')
1412
export class Popup extends CustomElementView {
1513
private animation!: string;
14+
private $target!: ElementView;
1615
private $bubble!: ElementView;
1716
isOpen = false;
1817

@@ -22,8 +21,8 @@ export class Popup extends CustomElementView {
2221
this.$bubble = this.$('.popup-body')!;
2322
this.$bubble.hide();
2423

25-
const $target = this.$('.popup-target')!;
26-
$target.on('click', () => this.toggleOpen());
24+
this.$target = this.$('.popup-target')!;
25+
this.$target.on('click', () => this.toggleOpen());
2726
this.on('clickOutside', () => this.close());
2827
for (const $a of this.$bubble.$$('a')) $a.on('click', () => this.close());
2928

@@ -42,6 +41,8 @@ export class Popup extends CustomElementView {
4241
if (this.isOpen) return;
4342
this.isOpen = true;
4443

44+
this.$target.setAttr('aria-expanded', true);
45+
4546
this.addClass('active');
4647
this.$bubble.enter(this.animation, 150);
4748
this.$bubble.setAttr('role', 'dialog');
@@ -53,9 +54,12 @@ export class Popup extends CustomElementView {
5354
if (!this.isOpen) return;
5455
this.isOpen = false;
5556

57+
this.$target.setAttr('aria-expanded', false);
58+
5659
this.removeClass('active');
5760
this.$bubble.exit(this.animation, 150);
5861
this.$bubble.removeAttr('role');
5962
this.trigger('close');
63+
this.$target.focus();
6064
}
6165
}

0 commit comments

Comments
 (0)