Skip to content

Commit df59fe0

Browse files
author
Ryan A. Johnson
committed
feat(HXPillElement): add declarative functionality
* Add `dismiss()` to simulate clicking "x"
1 parent 82e29e6 commit df59fe0

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

docs/elements/hx-pill/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<h2 id="methods">Methods</h2>
4040
<dl>
4141
<dt>dismiss()</dt>
42-
<dd>Dismisses the pill.</dd>
42+
<dd>Dismiss the pill (removes element from the DOM).</dd>
4343
</dl>
4444
</section>
4545
{% endblock %}

src/helix-ui/elements/HXPillElement.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,19 @@ export class HXPillElement extends HXElement {
3939
}
4040

4141
/**
42-
* Programmatically dismiss the pill (removes element from the DOM).
42+
* Dismiss the pill (removes element from the DOM)
4343
*/
4444
dismiss () {
45-
this.remove();
45+
if (this.$emit('dismiss')) {
46+
// only if event was not canceled by consumer
47+
this.remove();
48+
}
4649
}
4750

4851
/** @private */
4952
_onDismiss (evt) {
5053
evt.preventDefault();
51-
52-
if (this.$emit('dismiss')) {
53-
// only if event was not canceled by consumer
54-
this.dismiss();
55-
}
54+
this.dismiss();
5655
}
5756

5857
/** @private */

0 commit comments

Comments
 (0)