Skip to content

Commit

Permalink
Fix primefaces#4567: DropDown: Labels unassociated from DropDown unle…
Browse files Browse the repository at this point in the history
…ss :editable="true"
  • Loading branch information
FlipWarthog committed Oct 13, 2023
1 parent 4195fd7 commit 5aef649
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions components/lib/dropdown/Dropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export default {
outsideClickListener: null,
scrollHandler: null,
resizeListener: null,
labelClickListener: null,
overlay: null,
list: null,
virtualScroller: null,
Expand Down Expand Up @@ -218,6 +219,7 @@ export default {
this.id = this.id || UniqueComponentId();
this.autoUpdateModel();
this.bindLabelClickListener();
},
updated() {
if (this.overlayVisible && this.isModelValueChanged) {
Expand All @@ -229,6 +231,7 @@ export default {
beforeUnmount() {
this.unbindOutsideClickListener();
this.unbindResizeListener();
this.unbindLabelClickListener();
if (this.scrollHandler) {
this.scrollHandler.destroy();
Expand Down Expand Up @@ -704,6 +707,29 @@ export default {
this.resizeListener = null;
}
},
bindLabelClickListener() {
if (!this.editable && !this.labelClickListener) {
const label = document.querySelector(`label[for="${this.inputId}"]`);
if (label && DomHandler.isVisible(label)) {
this.labelClickListener = () => {
DomHandler.focus(this.$refs.focusInput);
}
label.addEventListener("click", this.labelClickListener);
}
}
},
unbindLabelClickListener() {
if (this.labelClickListener) {
const label = document.querySelector(`label[for="${this.inputId}"]`);
if (label && DomHandler.isVisible(label)) {
label.removeEventListener('click', this.labelClickListener);
}
}
},
hasFocusableElements() {
return DomHandler.getFocusableElements(this.overlay, ':not([data-p-hidden-focusable="true"])').length > 0;
},
Expand Down

0 comments on commit 5aef649

Please sign in to comment.