Skip to content

Add shadow DOM getter for all types of elements #115

@forgetso

Description

@forgetso

At the moment, a shadow DOM search is performed for matching inputs with the same name or value. This type of search could be extended to any DOM element with the same matching value in a shadow DOM.

function replaceInInputShadow(
input: HTMLInputElement | HTMLTextAreaElement,
config: SearchReplaceConfig,
newValue: string
) {
if (config.shadowRoots.length) {
config.shadowRoots.map((shadowRoot) => {
let shadowInputs = Array.from(shadowRoot.querySelectorAll(`input[id="${input['id']}"]`))
if (!shadowInputs.length) {
shadowInputs = Array.from(shadowRoot.querySelectorAll(`input[name="${input['name']}"]`))
}
if (!shadowInputs.length) {
shadowInputs = Array.from(shadowRoot.querySelectorAll(`input[value="${input['value']}"]`))
}
if (!shadowInputs.length) {
// perform less exact search
shadowInputs = Array.from(shadowRoot.querySelectorAll(`*[value="${input['value']}"]`))
}
if (shadowInputs.length) {
shadowInputs.map((shadowInput) => {
shadowInput['value'] = newValue
shadowInput.dispatchEvent(new Event('input', { bubbles: true }))
})
shadowRoot.host.dispatchEvent(new Event('input', { bubbles: true }))
}
})
}
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions