mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 09:16:38 +00:00
Make sure tap listener is added at most once. (#745)
* Make sure tap listener is added at most once. * Add comment
This commit is contained in:
parent
c8c21e6fac
commit
6b180988fd
@ -77,6 +77,13 @@ class HaEntitiesCard extends
|
||||
};
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
// We need to save a single bound function reference to ensure the event listener
|
||||
// can identify it properly.
|
||||
this.entityTapped = this.entityTapped.bind(this);
|
||||
}
|
||||
|
||||
computeTitle(states, groupEntity, localize) {
|
||||
if (groupEntity) {
|
||||
return window.hassUtil.computeStateName(groupEntity).trim();
|
||||
@ -98,9 +105,13 @@ class HaEntitiesCard extends
|
||||
}
|
||||
|
||||
addTapEvents() {
|
||||
const cards = this.root.querySelectorAll('.state.more-info');
|
||||
const cards = this.root.querySelectorAll('.state');
|
||||
cards.forEach((card) => {
|
||||
card.addEventListener('tap', this.entityTapped.bind(this));
|
||||
if (card.classList.contains('more-info')) {
|
||||
card.addEventListener('tap', this.entityTapped);
|
||||
} else {
|
||||
card.removeEventListener('tap', this.entityTapped);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user