|
1 | 1 | (() => { |
2 | 2 | class JoomlaAlertElement extends HTMLElement { |
3 | 3 | /* Attributes to monitor */ |
4 | | - static get observedAttributes() { return ['type', 'dismiss', 'acknowledge', 'href']; } |
| 4 | + static get observedAttributes() { return ['type', 'role', 'dismiss', 'acknowledge', 'href']; } |
5 | 5 |
|
6 | 6 | get type() { return this.getAttribute('type'); } |
7 | 7 |
|
8 | 8 | set type(value) { return this.setAttribute('type', value); } |
9 | 9 |
|
| 10 | + get role() { return this.getAttribute('role'); } |
| 11 | + |
| 12 | + set role(value) { return this.setAttribute('role', value); } |
| 13 | + |
10 | 14 | get dismiss() { return this.getAttribute('dismiss'); } |
11 | 15 |
|
12 | 16 | get acknowledge() { return this.getAttribute('acknowledge'); } |
|
15 | 19 |
|
16 | 20 | /* Lifecycle, element appended to the DOM */ |
17 | 21 | connectedCallback() { |
18 | | - this.setAttribute('role', 'alertdialog'); |
19 | 22 | this.classList.add('joomla-alert--show'); |
20 | 23 |
|
21 | 24 | // Default to info |
22 | 25 | if (!this.type || ['info', 'warning', 'danger', 'success'].indexOf(this.type) === -1) { |
23 | 26 | this.setAttribute('type', 'info'); |
24 | 27 | } |
| 28 | + // Default to alert |
| 29 | + if (!this.role || ['alert', 'alertdialog'].indexOf(this.role) === -1) { |
| 30 | + this.setAttribute('role', 'alert'); |
| 31 | + } |
25 | 32 | // Append button |
26 | 33 | if ((this.hasAttribute('dismiss') || this.hasAttribute('acknowledge')) || ((this.hasAttribute('href') && this.getAttribute('href') !== '') |
27 | 34 | && !this.querySelector('button.joomla-alert--close') && !this.querySelector('button.joomla-alert-button--close'))) { |
|
50 | 57 | this.type = 'info'; |
51 | 58 | } |
52 | 59 | break; |
| 60 | + case 'role': |
| 61 | + if (!newValue || (newValue && ['alert', 'alertdialog'].indexOf(newValue) === -1)) { |
| 62 | + this.role = 'alert'; |
| 63 | + } |
| 64 | + break; |
53 | 65 | case 'dismiss': |
54 | 66 | case 'acknowledge': |
55 | 67 | if (!newValue || newValue === 'true') { |
|
0 commit comments