Skip to content

Commit 4fb1994

Browse files
Quywilsonge
authored andcommitted
Make role attribute configurable (#119)
1 parent 7f3efa2 commit 4fb1994

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/js/alert/alert.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
(() => {
22
class JoomlaAlertElement extends HTMLElement {
33
/* Attributes to monitor */
4-
static get observedAttributes() { return ['type', 'dismiss', 'acknowledge', 'href']; }
4+
static get observedAttributes() { return ['type', 'role', 'dismiss', 'acknowledge', 'href']; }
55

66
get type() { return this.getAttribute('type'); }
77

88
set type(value) { return this.setAttribute('type', value); }
99

10+
get role() { return this.getAttribute('role'); }
11+
12+
set role(value) { return this.setAttribute('role', value); }
13+
1014
get dismiss() { return this.getAttribute('dismiss'); }
1115

1216
get acknowledge() { return this.getAttribute('acknowledge'); }
@@ -15,13 +19,16 @@
1519

1620
/* Lifecycle, element appended to the DOM */
1721
connectedCallback() {
18-
this.setAttribute('role', 'alertdialog');
1922
this.classList.add('joomla-alert--show');
2023

2124
// Default to info
2225
if (!this.type || ['info', 'warning', 'danger', 'success'].indexOf(this.type) === -1) {
2326
this.setAttribute('type', 'info');
2427
}
28+
// Default to alert
29+
if (!this.role || ['alert', 'alertdialog'].indexOf(this.role) === -1) {
30+
this.setAttribute('role', 'alert');
31+
}
2532
// Append button
2633
if ((this.hasAttribute('dismiss') || this.hasAttribute('acknowledge')) || ((this.hasAttribute('href') && this.getAttribute('href') !== '')
2734
&& !this.querySelector('button.joomla-alert--close') && !this.querySelector('button.joomla-alert-button--close'))) {
@@ -50,6 +57,11 @@
5057
this.type = 'info';
5158
}
5259
break;
60+
case 'role':
61+
if (!newValue || (newValue && ['alert', 'alertdialog'].indexOf(newValue) === -1)) {
62+
this.role = 'alert';
63+
}
64+
break;
5365
case 'dismiss':
5466
case 'acknowledge':
5567
if (!newValue || newValue === 'true') {

0 commit comments

Comments
 (0)