This commit is contained in:
Vanessa 2023-12-04 00:37:57 +08:00
parent d1c5c9ac7d
commit 2f34408577
4 changed files with 11 additions and 7 deletions

View file

@ -7,10 +7,10 @@ const update = (inputElement: HTMLInputElement, clearElement: Element, right: nu
} else {
clearElement.classList.remove("fn__none");
if (right) {
inputElement.style.setProperty('padding-right', `${right * 2 + clearElement.clientWidth}px`, 'important');
inputElement.style.setProperty("padding-right", `${right * 2 + clearElement.clientWidth}px`, "important");
}
}
}
};
export const addClearButton = (options: {
inputElement: HTMLInputElement,
clearCB?: () => void,
@ -19,7 +19,7 @@ export const addClearButton = (options: {
className?: string
}) => {
options.inputElement.insertAdjacentHTML("afterend",
`<svg class="${options.className || "b3-form__icon-clear"}" style="${options.right ? "right: " + options.right + "px" : ""}${options.height ? "height:" + options.height + "px" : ""}">
`<svg class="${options.className || "b3-form__icon-clear"}" style="${options.right ? "right: " + options.right + "px;" : ""}${options.height ? "height:" + options.height + "px" : ""}">
<use xlink:href="#iconCloseRound"></use></svg>`);
const clearElement = options.inputElement.nextElementSibling;
clearElement.addEventListener("click", () => {
@ -29,7 +29,7 @@ export const addClearButton = (options: {
if (options.clearCB) {
options.clearCB();
}
})
});
options.inputElement.addEventListener("input", () => {
update(options.inputElement, clearElement, options.right);
});