Float field labels on focus or value, Material outlined style.
Some checks failed
Mirror to Gitea / mirror (push) Has been cancelled
Some checks failed
Mirror to Gitea / mirror (push) Has been cancelled
Empty labels sit inside the box; they move up to the border when the field is focused or has a value. Co-authored-by: Diaco Soltanpour <s-diaco@users.noreply.github.com>
This commit is contained in:
@@ -184,31 +184,49 @@
|
|||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
.fields { display: grid; gap: 18px; }
|
.fields { display: grid; gap: 22px; }
|
||||||
|
|
||||||
.field {
|
.field {
|
||||||
position: relative;
|
position: relative;
|
||||||
display: block;
|
display: block;
|
||||||
padding-top: 8px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.field-label {
|
.field-label {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
z-index: 1;
|
z-index: 2;
|
||||||
top: 0;
|
top: 50%;
|
||||||
left: 11px;
|
left: 12px;
|
||||||
padding: 0 4px;
|
padding: 0 4px;
|
||||||
background: var(--label-bg);
|
background: transparent;
|
||||||
color: var(--primary);
|
color: var(--text-muted);
|
||||||
font-size: 0.75rem;
|
font-size: 1rem;
|
||||||
line-height: 1rem;
|
line-height: 1;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
transform-origin: left center;
|
||||||
|
transition:
|
||||||
|
top 180ms var(--ease),
|
||||||
|
font-size 180ms var(--ease),
|
||||||
|
color 180ms var(--ease),
|
||||||
|
background-color 180ms var(--ease);
|
||||||
|
}
|
||||||
|
|
||||||
|
.field.is-floated .field-label,
|
||||||
|
.field:focus-within .field-label {
|
||||||
|
top: 0;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
background: var(--label-bg);
|
||||||
|
color: var(--text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.field:focus-within .field-label {
|
||||||
|
color: var(--primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
select, input {
|
select, input {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
min-height: 54px;
|
min-height: 54px;
|
||||||
padding: 16px 12px 6px;
|
padding: 16px 12px;
|
||||||
border: 1px solid var(--border-strong);
|
border: 1px solid var(--border-strong);
|
||||||
border-radius: var(--radius-sm);
|
border-radius: var(--radius-sm);
|
||||||
outline: none;
|
outline: none;
|
||||||
@@ -218,6 +236,14 @@
|
|||||||
transition: border-color 150ms var(--ease), box-shadow 150ms var(--ease);
|
transition: border-color 150ms var(--ease), box-shadow 150ms var(--ease);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.field input::placeholder {
|
||||||
|
color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field:focus-within input::placeholder {
|
||||||
|
color: var(--text-dim);
|
||||||
|
}
|
||||||
|
|
||||||
.combobox-input {
|
.combobox-input {
|
||||||
padding-right: 36px;
|
padding-right: 36px;
|
||||||
cursor: text;
|
cursor: text;
|
||||||
@@ -487,6 +513,14 @@
|
|||||||
});
|
});
|
||||||
syncThemeToggle();
|
syncThemeToggle();
|
||||||
|
|
||||||
|
function syncFloat(inputEl) {
|
||||||
|
const field = inputEl.closest(".field");
|
||||||
|
if (!field) return;
|
||||||
|
const filled = inputEl.value.trim().length > 0;
|
||||||
|
const focused = document.activeElement === inputEl;
|
||||||
|
field.classList.toggle("is-floated", filled || focused);
|
||||||
|
}
|
||||||
|
|
||||||
// Builds a searchable combobox. The underlying <select> stays as the
|
// Builds a searchable combobox. The underlying <select> stays as the
|
||||||
// semantic source of truth; the visible widget is a text <input> plus a
|
// semantic source of truth; the visible widget is a text <input> plus a
|
||||||
// listbox panel that filters options as the user types.
|
// listbox panel that filters options as the user types.
|
||||||
@@ -560,6 +594,7 @@
|
|||||||
inputDirty = false;
|
inputDirty = false;
|
||||||
close();
|
close();
|
||||||
inputEl.focus();
|
inputEl.focus();
|
||||||
|
syncFloat(inputEl);
|
||||||
};
|
};
|
||||||
|
|
||||||
const syncDisabled = () => {
|
const syncDisabled = () => {
|
||||||
@@ -595,13 +630,18 @@
|
|||||||
}
|
}
|
||||||
inputDirty = false;
|
inputDirty = false;
|
||||||
syncDisabled();
|
syncDisabled();
|
||||||
|
syncFloat(inputEl);
|
||||||
};
|
};
|
||||||
|
|
||||||
inputEl.addEventListener("focus", open);
|
inputEl.addEventListener("focus", () => {
|
||||||
|
syncFloat(inputEl);
|
||||||
|
open();
|
||||||
|
});
|
||||||
inputEl.addEventListener("input", () => {
|
inputEl.addEventListener("input", () => {
|
||||||
inputDirty = true;
|
inputDirty = true;
|
||||||
if (!openState) open();
|
if (!openState) open();
|
||||||
filter();
|
filter();
|
||||||
|
syncFloat(inputEl);
|
||||||
});
|
});
|
||||||
inputEl.addEventListener("blur", () => {
|
inputEl.addEventListener("blur", () => {
|
||||||
// Defer close so a mousedown on a panel option can fire first.
|
// Defer close so a mousedown on a panel option can fire first.
|
||||||
@@ -611,6 +651,7 @@
|
|||||||
inputDirty = false;
|
inputDirty = false;
|
||||||
}
|
}
|
||||||
close();
|
close();
|
||||||
|
syncFloat(inputEl);
|
||||||
}, 0);
|
}, 0);
|
||||||
});
|
});
|
||||||
inputEl.addEventListener("keydown", (event) => {
|
inputEl.addEventListener("keydown", (event) => {
|
||||||
@@ -750,6 +791,11 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
serialInput.addEventListener("focus", () => syncFloat(serialInput));
|
||||||
|
serialInput.addEventListener("input", () => syncFloat(serialInput));
|
||||||
|
serialInput.addEventListener("blur", () => syncFloat(serialInput));
|
||||||
|
syncFloat(serialInput);
|
||||||
|
|
||||||
window.addEventListener("pywebviewready", initialize);
|
window.addEventListener("pywebviewready", initialize);
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ def test_ui_asset_exists_and_has_required_bridge_content():
|
|||||||
"get_inks(setDropdown.value)",
|
"get_inks(setDropdown.value)",
|
||||||
"api.create(",
|
"api.create(",
|
||||||
"finally",
|
"finally",
|
||||||
|
"is-floated",
|
||||||
|
"syncFloat(",
|
||||||
):
|
):
|
||||||
assert expected in content
|
assert expected in content
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user