mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 00:50:13 +01:00
This commit is contained in:
parent
4b55e2e306
commit
3ea2741e5f
5 changed files with 78 additions and 30 deletions
27
app/src/util/addClearButton.ts
Normal file
27
app/src/util/addClearButton.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
const update = (inputElement: HTMLInputElement, clearElement: Element, right = 8) => {
|
||||
if (inputElement.value === "") {
|
||||
clearElement.classList.add("fn__none");
|
||||
inputElement.style.paddingRight = "";
|
||||
} else {
|
||||
clearElement.classList.remove("fn__none");
|
||||
inputElement.style.setProperty('padding-right', `${right * 2 + clearElement.clientWidth}px`, 'important');
|
||||
}
|
||||
}
|
||||
export const addClearButton = (inputElement: HTMLInputElement, clearCB?: () => void, right = 8, height?: number) => {
|
||||
inputElement.insertAdjacentHTML("afterend",
|
||||
`<svg class="b3-form__icon-clear" style="right:${right}px;height: ${height || inputElement.clientHeight}px;">
|
||||
<use xlink:href="#iconCloseRound"></use></svg>`);
|
||||
const clearElement = inputElement.nextElementSibling;
|
||||
clearElement.addEventListener("click", () => {
|
||||
inputElement.value = "";
|
||||
inputElement.focus();
|
||||
update(inputElement, clearElement, right);
|
||||
if (clearCB) {
|
||||
clearCB();
|
||||
}
|
||||
})
|
||||
inputElement.addEventListener("input", () => {
|
||||
update(inputElement, clearElement, right);
|
||||
});
|
||||
update(inputElement, clearElement, right);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue