Skip to content

Add shadow DOM getter for all types of elements #115

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 }))
}
})
}
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions