Skip to content

Commit bdaad83

Browse files
author
Ryan A. Johnson
committed
feat(HXAlertElement): add delcarative functionality
* Add `submit()` to simulate clicking CTA * Update `dismiss()` to wrap event emission logic
1 parent 8b6bd33 commit bdaad83

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

docs/elements/hx-alert/index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@
4040
<h2 id="methods">Methods</h2>
4141
<dl>
4242
<dt>dismiss()</dt>
43-
<dd>Dismisses the alert.</dd>
43+
<dd>Dismiss the alert (removes element from the DOM).</dd>
44+
</dl>
45+
<dl>
46+
<dt>submit()</dt>
47+
<dd>Simulates a mouse click on the CTA.</dd>
4448
</dl>
4549
</section>
4650
{% endblock %}

src/helix-ui/elements/HXAlertElement.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,26 +166,32 @@ export class HXAlertElement extends HXElement {
166166
}
167167

168168
/**
169-
* Programmatically dismiss the alert (removes element from the DOM).
169+
* Dismiss the alert (removes element from the DOM).
170170
*/
171171
dismiss () {
172-
this.remove();
172+
if (this.$emit('dismiss')) {
173+
// only if event was not canceled by consumer
174+
this.remove();
175+
}
176+
}
177+
178+
/**
179+
* Simulate a mouse click on the CTA button.
180+
*/
181+
submit () {
182+
this.$emit('submit');
173183
}
174184

175185
/** @private */
176186
_onDismiss (evt) {
177187
evt.preventDefault();
178-
179-
if (this.$emit('dismiss')) {
180-
// only if event was not canceled by consumer
181-
this.dismiss();
182-
}
188+
this.dismiss();
183189
}
184190

185191
/** @private */
186192
_onSubmit (evt) {
187193
evt.preventDefault();
188-
this.$emit('submit');
194+
this.submit();
189195
}
190196

191197
/** @private */

0 commit comments

Comments
 (0)