Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 馃悰 selected option not preserved in image #280

Merged
merged 1 commit into from
Aug 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/cloneNode.ts
Expand Up @@ -101,6 +101,19 @@ function cloneInputValue<T extends HTMLElement>(nativeNode: T, clonedNode: T) {
}
}

function cloneSelectValue<T extends HTMLElement>(nativeNode: T, clonedNode: T) {
if (nativeNode instanceof HTMLSelectElement) {
const clonedSelect = clonedNode as any as HTMLSelectElement
const selectedOption = Array.from(clonedSelect.children).find(
(child) => nativeNode.value === child.getAttribute('value'),
)

if (selectedOption) {
selectedOption.setAttribute('selected', '')
}
}
}

async function decorate<T extends HTMLElement>(
nativeNode: T,
clonedNode: T,
Expand All @@ -113,6 +126,7 @@ async function decorate<T extends HTMLElement>(
.then(() => cloneCSSStyle(nativeNode, clonedNode))
.then(() => clonePseudoElements(nativeNode, clonedNode))
.then(() => cloneInputValue(nativeNode, clonedNode))
.then(() => cloneSelectValue(nativeNode, clonedNode))
.then(() => clonedNode)
}

Expand Down