mirror of
https://github.com/bitwarden/browser.git
synced 2025-01-03 18:28:13 +01:00
Fix input element lookup from label (#2102)
This commit is contained in:
parent
ec5a2299ca
commit
6a567ed3bf
@ -12,27 +12,24 @@ function getClickedElementIdentifier() {
|
|||||||
return invalidElement;
|
return invalidElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tagName = clickedEl.nodeName.toLowerCase();
|
const clickedTag = clickedEl.nodeName.toLowerCase();
|
||||||
let inputEl = null;
|
let inputEl = null;
|
||||||
|
|
||||||
// Try to identify the input element (which may not be the clicked element)
|
// Try to identify the input element (which may not be the clicked element)
|
||||||
if (inputTags.includes(tagName)) {
|
if (labelTags.includes(clickedTag)) {
|
||||||
inputEl = clickedEl;
|
let inputId = null;
|
||||||
} else if (labelTags.includes(tagName)) {
|
if (clickedTag === 'label') {
|
||||||
let inputName = null;
|
inputId = clickedEl.getAttribute('for');
|
||||||
if (tagName === 'label') {
|
|
||||||
inputName = clickedEl.getAttribute('for');
|
|
||||||
} else {
|
} else {
|
||||||
inputName = clickedEl.closest('label')?.getAttribute('for');
|
inputId = clickedEl.closest('label')?.getAttribute('for');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inputName != null) {
|
inputEl = document.getElementById(inputId);
|
||||||
inputEl = document.querySelector('input[name=' + inputName + '], select[name=' + inputName +
|
} else {
|
||||||
'], textarea[name=' + inputName + ']');
|
inputEl = clickedEl;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inputEl == null) {
|
if (inputEl == null || !inputTags.includes(inputEl.nodeName.toLowerCase())) {
|
||||||
return invalidElement;
|
return invalidElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user