HEL-349: fix night-mode selects, anchored date popover, and scrollbars
Native select lists and date calendars could not be reliably themed or positioned, so popovers now use existing fusion tokens and stay anchored to the trigger. Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
co-authored by
Cursor
multica-agent
parent
ed87fd8574
commit
f729e49710
+182
-5
@@ -63,6 +63,7 @@ img { display: block; }
|
||||
--material-toast: rgba(30, 30, 32, 0.92);
|
||||
--shadow-toast: 0 8px 24px rgba(0, 0, 0, 0.22);
|
||||
--shadow-seg: 0 1px 3px rgba(0, 0, 0, 0.10), 0 0 0 1px rgba(0, 0, 0, 0.03);
|
||||
color-scheme: light;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
color: var(--text);
|
||||
@@ -113,6 +114,7 @@ img { display: block; }
|
||||
--material-toast: rgba(54, 52, 47, 0.94);
|
||||
--shadow-toast: 0 8px 24px rgba(0, 0, 0, 0.50);
|
||||
--shadow-seg: 0 1px 3px rgba(0, 0, 0, 0.50), 0 0 0 1px rgba(255, 255, 255, 0.06);
|
||||
color-scheme: dark;
|
||||
background:
|
||||
radial-gradient(1200px 600px at 85% -10%, rgba(224, 83, 65, 0.07), transparent 60%),
|
||||
radial-gradient(900px 500px at -10% 110%, rgba(217, 180, 92, 0.06), transparent 55%),
|
||||
@@ -245,8 +247,8 @@ img { display: block; }
|
||||
/* — 筛选条:输入几何沿用 .search / 表单控件(34px 控件、9px 圆角、fill 底) — */
|
||||
.v-fusion .filter-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 14px 0; }
|
||||
.v-fusion .filter-bar select {
|
||||
height: 30px; padding: 0 10px; border-radius: 9px; font-size: 12.5px;
|
||||
border: 1px solid var(--hairline); background: var(--surface); color: var(--text);
|
||||
height: 30px; padding: 0 26px 0 10px; border-radius: 9px; font-size: 12.5px;
|
||||
border: 1px solid var(--hairline); background-color: var(--surface); color: var(--text);
|
||||
outline: none; transition: border-color 150ms ease, box-shadow 150ms ease;
|
||||
}
|
||||
.v-fusion .filter-bar select:focus { border-color: var(--focus-ring); box-shadow: 0 0 0 3px var(--focus-glow); }
|
||||
@@ -453,16 +455,17 @@ img { display: block; }
|
||||
.v-fusion .form-field label { font-size: 12px; font-weight: 600; color: var(--text-2); }
|
||||
.v-fusion .form-field input, .v-fusion .form-field select, .v-fusion .form-field textarea {
|
||||
height: 34px; padding: 0 11px; border-radius: 9px;
|
||||
border: 1px solid var(--hairline); background: var(--surface);
|
||||
border: 1px solid var(--hairline); background-color: var(--surface); color: var(--text);
|
||||
outline: none; font-size: 13.5px;
|
||||
transition: border-color 150ms ease, box-shadow 150ms ease;
|
||||
}
|
||||
.v-fusion .form-field select { padding-right: 28px; }
|
||||
.v-fusion .form-field textarea { height: auto; min-height: 68px; padding: 8px 11px; resize: vertical; }
|
||||
.v-fusion .form-field input:focus, .v-fusion .form-field select:focus, .v-fusion .form-field textarea:focus {
|
||||
border-color: var(--focus-ring); box-shadow: 0 0 0 3px var(--focus-glow);
|
||||
}
|
||||
.v-fusion .form-field[data-error] input, .v-fusion .form-field[data-error] select { border-color: var(--red); box-shadow: 0 0 0 3px var(--red-glow); animation: fusion-shake 300ms var(--ease-in-out); }
|
||||
.v-fusion .form-field input[disabled], .v-fusion .form-field select[disabled] { background: var(--fill); color: var(--text-3); cursor: not-allowed; }
|
||||
.v-fusion .form-field input[disabled], .v-fusion .form-field select[disabled] { background-color: var(--fill); color: var(--text-3); cursor: not-allowed; }
|
||||
.v-fusion .field-err { font-size: 11.5px; color: var(--red); min-height: 14px; }
|
||||
.v-fusion .field-hint { font-size: 11.5px; color: var(--text-3); }
|
||||
@keyframes fusion-shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
|
||||
@@ -727,10 +730,11 @@ img { display: block; }
|
||||
.v-fusion .cr-ctl input[type="text"], .v-fusion .cr-ctl input[type="number"], .v-fusion .cr-ctl input[type="date"], .v-fusion .cr-ctl select {
|
||||
max-width: 100%;
|
||||
height: 34px; padding: 0 11px; border-radius: 9px;
|
||||
border: 1px solid var(--hairline); background: var(--surface); color: var(--text);
|
||||
border: 1px solid var(--hairline); background-color: var(--surface); color: var(--text);
|
||||
outline: none; font-size: 13.5px;
|
||||
transition: border-color 150ms ease, box-shadow 150ms ease;
|
||||
}
|
||||
.v-fusion .cr-ctl select { padding-right: 28px; }
|
||||
.v-fusion .cr-ctl input[type="text"]:focus, .v-fusion .cr-ctl input[type="number"]:focus, .v-fusion .cr-ctl input[type="date"]:focus, .v-fusion .cr-ctl select:focus {
|
||||
border-color: var(--focus-ring); box-shadow: 0 0 0 3px var(--focus-glow);
|
||||
}
|
||||
@@ -948,6 +952,179 @@ img { display: block; }
|
||||
}
|
||||
.v-fusion .flash-banner--ok { background: var(--green-bg); color: var(--green); border-color: transparent; }
|
||||
.v-fusion select, .v-fusion input, .v-fusion textarea { font: inherit; color: inherit; }
|
||||
|
||||
/* HEL-349:全站 select 闭合态走 Token,避免夜间 UA 白底;箭头用 SVG 以便日夜换色 */
|
||||
.v-fusion select {
|
||||
appearance: none; -webkit-appearance: none;
|
||||
height: 34px; padding: 0 28px 0 11px; border-radius: 9px;
|
||||
border: 1px solid var(--hairline); background-color: var(--surface); color: var(--text);
|
||||
outline: none; font-size: 13.5px;
|
||||
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' viewBox='0 0 12 8'%3E%3Cpath stroke='%236e6e73' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M1.5 1.75 6 6.25l4.5-4.5'/%3E%3C/svg%3E");
|
||||
background-repeat: no-repeat; background-position: right 10px center; background-size: 12px 8px;
|
||||
transition: border-color 150ms ease, box-shadow 150ms ease, background-color 150ms ease;
|
||||
}
|
||||
.v-fusion[data-theme="night"] select {
|
||||
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' viewBox='0 0 12 8'%3E%3Cpath stroke='%23a9a49b' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M1.5 1.75 6 6.25l4.5-4.5'/%3E%3C/svg%3E");
|
||||
}
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
.v-fusion select:hover:not(:disabled) { background-color: var(--surface-2); }
|
||||
}
|
||||
.v-fusion select:focus, .v-fusion select:focus-visible {
|
||||
border-color: var(--focus-ring); box-shadow: 0 0 0 3px var(--focus-glow);
|
||||
}
|
||||
.v-fusion select:disabled {
|
||||
background-color: var(--fill); color: var(--text-3); cursor: not-allowed; opacity: 0.7;
|
||||
}
|
||||
.v-fusion option, .v-fusion optgroup {
|
||||
background-color: var(--surface); color: var(--text);
|
||||
}
|
||||
.v-fusion option:disabled { color: var(--text-3); }
|
||||
.v-fusion option:checked { background-color: var(--fill-strong); color: var(--text); }
|
||||
|
||||
/* HEL-349:日期输入走 Token;夜间日历图标用曜金,不刷整块纯金底 */
|
||||
.v-fusion input[type="date"] {
|
||||
color: var(--text); background-color: var(--surface); border: 1px solid var(--hairline);
|
||||
font-variant-numeric: tabular-nums;
|
||||
color-scheme: inherit;
|
||||
}
|
||||
.v-fusion input[type="date"]:focus, .v-fusion input[type="date"]:focus-visible {
|
||||
border-color: var(--focus-ring); box-shadow: 0 0 0 3px var(--focus-glow);
|
||||
}
|
||||
.v-fusion input[type="date"]:disabled {
|
||||
background-color: var(--fill); color: var(--text-3); cursor: not-allowed; opacity: 0.7;
|
||||
}
|
||||
.v-fusion input[type="date"]::-webkit-datetime-edit,
|
||||
.v-fusion input[type="date"]::-webkit-datetime-edit-fields-wrapper,
|
||||
.v-fusion input[type="date"]::-webkit-datetime-edit-text,
|
||||
.v-fusion input[type="date"]::-webkit-datetime-edit-year-field,
|
||||
.v-fusion input[type="date"]::-webkit-datetime-edit-month-field,
|
||||
.v-fusion input[type="date"]::-webkit-datetime-edit-day-field {
|
||||
color: var(--text);
|
||||
}
|
||||
.v-fusion input[type="date"]:disabled::-webkit-datetime-edit,
|
||||
.v-fusion input[type="date"]:disabled::-webkit-datetime-edit-fields-wrapper {
|
||||
color: var(--text-3);
|
||||
}
|
||||
.v-fusion input[type="date"]::-webkit-calendar-picker-indicator {
|
||||
width: 16px; height: 16px; cursor: pointer; opacity: 1;
|
||||
background-color: var(--text-3);
|
||||
-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' viewBox='0 0 16 16'%3E%3Crect x='2.25' y='3.25' width='11.5' height='10.5' rx='1.75' stroke='black' stroke-width='1.5'/%3E%3Cpath stroke='black' stroke-width='1.5' stroke-linecap='round' d='M2.25 6.5h11.5M5.5 2.25v2.5M10.5 2.25v2.5'/%3E%3C/svg%3E") center / 16px no-repeat;
|
||||
mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' viewBox='0 0 16 16'%3E%3Crect x='2.25' y='3.25' width='11.5' height='10.5' rx='1.75' stroke='black' stroke-width='1.5'/%3E%3Cpath stroke='black' stroke-width='1.5' stroke-linecap='round' d='M2.25 6.5h11.5M5.5 2.25v2.5M10.5 2.25v2.5'/%3E%3C/svg%3E") center / 16px no-repeat;
|
||||
}
|
||||
.v-fusion[data-theme="night"] input[type="date"]::-webkit-calendar-picker-indicator {
|
||||
background-color: var(--gold);
|
||||
}
|
||||
|
||||
/* HEL-349:自定义锚定弹层(下拉 / 日历),fixed 以免被卡片 overflow 裁切 */
|
||||
.v-fusion .jn-pop {
|
||||
position: fixed; z-index: 80;
|
||||
background: var(--surface); color: var(--text);
|
||||
border: 1px solid var(--hairline); border-radius: 14px;
|
||||
box-shadow: var(--shadow-toast);
|
||||
font-size: 13px;
|
||||
}
|
||||
.v-fusion[data-theme="night"] .jn-pop {
|
||||
background: var(--surface-2);
|
||||
border-color: var(--gold-line);
|
||||
}
|
||||
.v-fusion .jn-pop[hidden] { display: none !important; }
|
||||
|
||||
.v-fusion .jn-menu {
|
||||
max-height: min(280px, calc(100vh - 16px));
|
||||
overflow-y: auto; overscroll-behavior: contain;
|
||||
padding: 6px; min-width: 120px;
|
||||
}
|
||||
.v-fusion .jn-menu-opt {
|
||||
display: block; width: 100%; text-align: left;
|
||||
padding: 7px 10px; border-radius: 8px;
|
||||
color: var(--text); background: transparent;
|
||||
font-size: 13px; line-height: 1.4; white-space: nowrap;
|
||||
}
|
||||
.v-fusion .jn-menu-opt[aria-selected="true"] {
|
||||
background: var(--accent-soft); color: var(--accent); font-weight: 650;
|
||||
}
|
||||
.v-fusion[data-theme="night"] .jn-menu-opt[aria-selected="true"] {
|
||||
background: var(--gold-soft); color: var(--gold);
|
||||
}
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
.v-fusion .jn-menu-opt:hover:not(:disabled) { background: var(--hover); }
|
||||
.v-fusion .jn-menu-opt[aria-selected="true"]:hover:not(:disabled) { background: var(--accent-soft); }
|
||||
.v-fusion[data-theme="night"] .jn-menu-opt[aria-selected="true"]:hover:not(:disabled) { background: var(--gold-soft); }
|
||||
}
|
||||
.v-fusion .jn-menu-opt:disabled, .v-fusion .jn-menu-opt[aria-disabled="true"] {
|
||||
color: var(--text-3); cursor: not-allowed; opacity: 0.7;
|
||||
}
|
||||
.v-fusion .jn-menu-opt:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; }
|
||||
|
||||
.v-fusion .jn-dp { width: 280px; padding: 12px; }
|
||||
.v-fusion .jn-dp-head {
|
||||
display: flex; align-items: center; justify-content: space-between; gap: 8px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.v-fusion .jn-dp-month {
|
||||
font-size: 13.5px; font-weight: 650; letter-spacing: -0.01em;
|
||||
font-variant-numeric: tabular-nums; color: var(--text);
|
||||
}
|
||||
.v-fusion[data-theme="night"] .jn-dp-month { color: var(--gold); }
|
||||
.v-fusion .jn-dp-nav {
|
||||
width: 28px; height: 28px; border-radius: 7px; flex: 0 0 auto;
|
||||
color: var(--text-2); font-size: 16px; line-height: 1;
|
||||
display: inline-flex; align-items: center; justify-content: center;
|
||||
transition: background-color 120ms ease, color 120ms ease, transform 160ms var(--ease-out);
|
||||
}
|
||||
.v-fusion .jn-dp-nav:active { transform: scale(0.94); }
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
.v-fusion .jn-dp-nav:hover { background: var(--hover); color: var(--text); }
|
||||
.v-fusion[data-theme="night"] .jn-dp-nav:hover { color: var(--gold); }
|
||||
}
|
||||
.v-fusion .jn-dp-week, .v-fusion .jn-dp-grid {
|
||||
display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px;
|
||||
}
|
||||
.v-fusion .jn-dp-week span {
|
||||
height: 26px; display: flex; align-items: center; justify-content: center;
|
||||
font-size: 11px; font-weight: 600; color: var(--text-3);
|
||||
}
|
||||
.v-fusion .jn-dp-day {
|
||||
height: 32px; border-radius: 8px;
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
font-variant-numeric: tabular-nums; font-size: 12.5px; color: var(--text);
|
||||
transition: background-color 120ms ease, color 120ms ease;
|
||||
}
|
||||
.v-fusion .jn-dp-day[data-out] { color: var(--text-3); }
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
.v-fusion .jn-dp-day:hover:not(:disabled) { background: var(--hover); }
|
||||
}
|
||||
.v-fusion .jn-dp-day[aria-selected="true"] {
|
||||
background: var(--accent-soft); color: var(--accent); font-weight: 650;
|
||||
}
|
||||
.v-fusion[data-theme="night"] .jn-dp-day[aria-selected="true"] {
|
||||
background: var(--gold-soft); color: var(--gold);
|
||||
box-shadow: inset 0 0 0 1px var(--gold-line);
|
||||
}
|
||||
.v-fusion .jn-dp-day[data-today]:not([aria-selected="true"]) {
|
||||
box-shadow: inset 0 0 0 1px var(--accent);
|
||||
}
|
||||
.v-fusion[data-theme="night"] .jn-dp-day[data-today]:not([aria-selected="true"]) {
|
||||
box-shadow: inset 0 0 0 1px var(--gold-line); color: var(--gold);
|
||||
}
|
||||
.v-fusion .jn-dp-day:disabled {
|
||||
color: var(--text-3); opacity: 0.45; cursor: not-allowed; box-shadow: none;
|
||||
}
|
||||
.v-fusion .jn-dp-foot { display: flex; justify-content: flex-end; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--hairline); }
|
||||
|
||||
/* HEL-349:夜间滚动条轨道融入深底、滑块克制曜金;日间保持 UA 中性样式 */
|
||||
.v-fusion[data-theme="night"] {
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: var(--gold-line) var(--bg);
|
||||
}
|
||||
.v-fusion[data-theme="night"] ::-webkit-scrollbar { width: 8px; height: 8px; }
|
||||
.v-fusion[data-theme="night"] ::-webkit-scrollbar-track { background: var(--bg); }
|
||||
.v-fusion[data-theme="night"] ::-webkit-scrollbar-thumb {
|
||||
background-color: var(--gold-line); border-radius: 999px;
|
||||
border: 2px solid var(--bg); background-clip: padding-box;
|
||||
}
|
||||
.v-fusion[data-theme="night"] ::-webkit-scrollbar-thumb:hover { background-color: var(--gold); }
|
||||
.v-fusion[data-theme="night"] ::-webkit-scrollbar-corner { background: var(--bg); }
|
||||
/* 分段控件在真实系统中以链接实现时与按钮同形 */
|
||||
.v-fusion .seg a {
|
||||
display: inline-flex; align-items: center; height: 26px; padding: 0 12px;
|
||||
|
||||
+360
-1
@@ -387,6 +387,312 @@ function initCalc() {
|
||||
if ($("[data-calc-discount]", r)) { renderDiscount(); renderDcHist(); }
|
||||
}
|
||||
|
||||
/* ============================================================
|
||||
HEL-349 · 自定义锚定弹层(下拉 / 日历)
|
||||
原生 select 展开列表与 input[type=date] 日历无法可靠换肤/定位,
|
||||
用现有 fusion 栈做 fixed 锚定层;原生控件仍负责取值与提交。
|
||||
============================================================ */
|
||||
const WEEKDAYS = ["日", "一", "二", "三", "四", "五", "六"];
|
||||
let popHost = null;
|
||||
let menuEl = null;
|
||||
let dpEl = null;
|
||||
let popAnchor = null;
|
||||
let popKind = null;
|
||||
let dpView = null;
|
||||
let dpFocusYmd = null;
|
||||
let popRepositionBound = false;
|
||||
|
||||
function popRoot() {
|
||||
return root() || document.body;
|
||||
}
|
||||
function ensurePops() {
|
||||
const host = popRoot();
|
||||
if (popHost === host && menuEl && dpEl) return;
|
||||
popHost = host;
|
||||
if (menuEl && menuEl.parentNode) menuEl.remove();
|
||||
if (dpEl && dpEl.parentNode) dpEl.remove();
|
||||
menuEl = document.createElement("div");
|
||||
menuEl.id = "jn-select-menu";
|
||||
menuEl.className = "jn-pop jn-menu";
|
||||
menuEl.hidden = true;
|
||||
menuEl.setAttribute("role", "listbox");
|
||||
menuEl.setAttribute("tabindex", "-1");
|
||||
dpEl = document.createElement("div");
|
||||
dpEl.id = "jn-datepicker";
|
||||
dpEl.className = "jn-pop jn-dp";
|
||||
dpEl.hidden = true;
|
||||
dpEl.setAttribute("role", "dialog");
|
||||
dpEl.setAttribute("aria-label", "选择日期");
|
||||
host.appendChild(menuEl);
|
||||
host.appendChild(dpEl);
|
||||
}
|
||||
function placePopover(pop, anchor) {
|
||||
const gap = 6, margin = 8;
|
||||
pop.hidden = false;
|
||||
pop.style.top = "0px";
|
||||
pop.style.left = "0px";
|
||||
const ar = anchor.getBoundingClientRect();
|
||||
const pr = pop.getBoundingClientRect();
|
||||
const vw = window.innerWidth, vh = window.innerHeight;
|
||||
let top = ar.bottom + gap;
|
||||
if (top + pr.height > vh - margin && ar.top - gap - pr.height >= margin) {
|
||||
top = ar.top - gap - pr.height;
|
||||
}
|
||||
top = Math.min(Math.max(margin, top), Math.max(margin, vh - pr.height - margin));
|
||||
let left = ar.left;
|
||||
if (left + pr.width > vw - margin) left = vw - pr.width - margin;
|
||||
left = Math.max(margin, left);
|
||||
pop.style.top = Math.round(top) + "px";
|
||||
pop.style.left = Math.round(left) + "px";
|
||||
if (pop === menuEl) {
|
||||
pop.style.minWidth = Math.round(ar.width) + "px";
|
||||
pop.style.maxWidth = Math.min(480, vw - margin * 2) + "px";
|
||||
}
|
||||
}
|
||||
function repositionOpenPop() {
|
||||
if (!popAnchor || !popKind) return;
|
||||
const pop = popKind === "menu" ? menuEl : dpEl;
|
||||
if (!pop || pop.hidden) return;
|
||||
if (!popAnchor.isConnected) { closePops(); return; }
|
||||
placePopover(pop, popAnchor);
|
||||
}
|
||||
function bindPopReposition(on) {
|
||||
if (on && !popRepositionBound) {
|
||||
window.addEventListener("resize", repositionOpenPop);
|
||||
window.addEventListener("scroll", repositionOpenPop, true);
|
||||
popRepositionBound = true;
|
||||
} else if (!on && popRepositionBound) {
|
||||
window.removeEventListener("resize", repositionOpenPop);
|
||||
window.removeEventListener("scroll", repositionOpenPop, true);
|
||||
popRepositionBound = false;
|
||||
}
|
||||
}
|
||||
function closePops() {
|
||||
const prev = popAnchor;
|
||||
const kind = popKind;
|
||||
const ae = document.activeElement;
|
||||
const focusBack = !!(prev && ae && (ae === prev || (menuEl && menuEl.contains(ae)) || (dpEl && dpEl.contains(ae))));
|
||||
if (menuEl) {
|
||||
menuEl.hidden = true;
|
||||
menuEl.innerHTML = "";
|
||||
}
|
||||
if (dpEl) dpEl.hidden = true;
|
||||
if (prev) {
|
||||
prev.setAttribute("aria-expanded", "false");
|
||||
prev.removeAttribute("aria-controls");
|
||||
}
|
||||
popAnchor = null;
|
||||
popKind = null;
|
||||
bindPopReposition(false);
|
||||
if (focusBack) prev.focus();
|
||||
return !!kind;
|
||||
}
|
||||
|
||||
function nativeSelect(el) {
|
||||
return el && el.tagName === "SELECT" && !el.multiple && !(+el.size > 1);
|
||||
}
|
||||
function openSelectMenu(select) {
|
||||
if (!nativeSelect(select) || select.disabled) return;
|
||||
ensurePops();
|
||||
if (popKind === "menu" && popAnchor === select) { closePops(); return; }
|
||||
closePops();
|
||||
popAnchor = select;
|
||||
popKind = "menu";
|
||||
select.setAttribute("aria-expanded", "true");
|
||||
select.setAttribute("aria-controls", "jn-select-menu");
|
||||
menuEl.innerHTML = "";
|
||||
const opts = Array.from(select.options);
|
||||
opts.forEach((opt, i) => {
|
||||
const btn = document.createElement("button");
|
||||
btn.type = "button";
|
||||
btn.className = "jn-menu-opt";
|
||||
btn.setAttribute("role", "option");
|
||||
btn.dataset.index = String(i);
|
||||
btn.textContent = opt.textContent;
|
||||
if (opt.disabled) {
|
||||
btn.disabled = true;
|
||||
btn.setAttribute("aria-disabled", "true");
|
||||
}
|
||||
if (opt.selected) btn.setAttribute("aria-selected", "true");
|
||||
menuEl.appendChild(btn);
|
||||
});
|
||||
placePopover(menuEl, select);
|
||||
bindPopReposition(true);
|
||||
const active = menuEl.querySelector(".jn-menu-opt[aria-selected='true']:not(:disabled)") || menuEl.querySelector(".jn-menu-opt:not(:disabled)");
|
||||
if (active) active.focus();
|
||||
}
|
||||
function commitSelect(index) {
|
||||
const select = popAnchor;
|
||||
if (!nativeSelect(select)) { closePops(); return; }
|
||||
const opt = select.options[index];
|
||||
if (!opt || opt.disabled) return;
|
||||
if (select.selectedIndex !== index) {
|
||||
select.selectedIndex = index;
|
||||
select.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
select.dispatchEvent(new Event("change", { bubbles: true }));
|
||||
}
|
||||
closePops();
|
||||
select.focus();
|
||||
}
|
||||
|
||||
function parseLimit(v) {
|
||||
const s = String(v || "").trim();
|
||||
return /^\d{4}-\d{2}-\d{2}$/.test(s) ? s : "";
|
||||
}
|
||||
function inDateRange(ymd, min, max) {
|
||||
if (min && ymd < min) return false;
|
||||
if (max && ymd > max) return false;
|
||||
return true;
|
||||
}
|
||||
function renderDatePicker() {
|
||||
if (!dpEl || !popAnchor) return;
|
||||
const input = popAnchor;
|
||||
const min = parseLimit(input.min), max = parseLimit(input.max);
|
||||
const selected = parseLimit(input.value);
|
||||
const today = cYmd(new Date());
|
||||
if (!dpView) {
|
||||
const seed = cParseYmd(selected) || new Date();
|
||||
dpView = { y: seed.getFullYear(), m: seed.getMonth() };
|
||||
}
|
||||
if (!dpFocusYmd) dpFocusYmd = selected || today;
|
||||
const y = dpView.y, m = dpView.m;
|
||||
const first = new Date(y, m, 1);
|
||||
const startDow = first.getDay();
|
||||
const gridStart = new Date(y, m, 1 - startDow);
|
||||
let days = "";
|
||||
for (let i = 0; i < 42; i++) {
|
||||
const d = new Date(gridStart.getFullYear(), gridStart.getMonth(), gridStart.getDate() + i);
|
||||
const ymd = cYmd(d);
|
||||
const out = d.getMonth() !== m;
|
||||
const disabled = !inDateRange(ymd, min, max);
|
||||
const sel = selected && ymd === selected;
|
||||
const isFocus = ymd === dpFocusYmd;
|
||||
days += `<button type="button" class="jn-dp-day" data-ymd="${ymd}"${out ? " data-out" : ""}${ymd === today ? " data-today" : ""}${sel ? ' aria-selected="true"' : ""}${disabled ? " disabled" : ""} tabindex="${isFocus && !disabled ? "0" : "-1"}">${d.getDate()}</button>`;
|
||||
}
|
||||
dpEl.innerHTML = `
|
||||
<div class="jn-dp-head">
|
||||
<button type="button" class="jn-dp-nav" data-dp-nav="-1" aria-label="上一月">‹</button>
|
||||
<div class="jn-dp-month" aria-live="polite">${y}年${m + 1}月</div>
|
||||
<button type="button" class="jn-dp-nav" data-dp-nav="1" aria-label="下一月">›</button>
|
||||
</div>
|
||||
<div class="jn-dp-week">${WEEKDAYS.map((w) => `<span>${w}</span>`).join("")}</div>
|
||||
<div class="jn-dp-grid">${days}</div>
|
||||
<div class="jn-dp-foot"><button type="button" class="btn btn--plain btn--sm" data-dp-today>今天</button></div>`;
|
||||
const focusBtn = dpEl.querySelector(`.jn-dp-day[data-ymd="${dpFocusYmd}"]:not(:disabled)`) || dpEl.querySelector(".jn-dp-day:not(:disabled)");
|
||||
if (focusBtn) {
|
||||
dpFocusYmd = focusBtn.dataset.ymd;
|
||||
focusBtn.tabIndex = 0;
|
||||
focusBtn.focus();
|
||||
}
|
||||
}
|
||||
function openDatePicker(input) {
|
||||
if (!input || input.type !== "date" || input.disabled || input.readOnly) return;
|
||||
ensurePops();
|
||||
if (popKind === "date" && popAnchor === input) { closePops(); return; }
|
||||
closePops();
|
||||
popAnchor = input;
|
||||
popKind = "date";
|
||||
input.setAttribute("aria-expanded", "true");
|
||||
input.setAttribute("aria-controls", "jn-datepicker");
|
||||
input.setAttribute("aria-haspopup", "dialog");
|
||||
const seed = cParseYmd(input.value) || new Date();
|
||||
dpView = { y: seed.getFullYear(), m: seed.getMonth() };
|
||||
dpFocusYmd = parseLimit(input.value) || cYmd(new Date());
|
||||
renderDatePicker();
|
||||
placePopover(dpEl, input);
|
||||
bindPopReposition(true);
|
||||
}
|
||||
function commitDate(ymd) {
|
||||
const input = popAnchor;
|
||||
if (!input || input.type !== "date") { closePops(); return; }
|
||||
const min = parseLimit(input.min), max = parseLimit(input.max);
|
||||
if (!inDateRange(ymd, min, max)) return;
|
||||
if (input.value !== ymd) {
|
||||
input.value = ymd;
|
||||
input.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
input.dispatchEvent(new Event("change", { bubbles: true }));
|
||||
}
|
||||
closePops();
|
||||
input.focus();
|
||||
}
|
||||
function shiftDpFocus(days) {
|
||||
const cur = cParseYmd(dpFocusYmd) || new Date();
|
||||
cur.setDate(cur.getDate() + days);
|
||||
dpFocusYmd = cYmd(cur);
|
||||
dpView = { y: cur.getFullYear(), m: cur.getMonth() };
|
||||
renderDatePicker();
|
||||
repositionOpenPop();
|
||||
}
|
||||
function shiftDpMonth(delta) {
|
||||
if (!dpView) return;
|
||||
const d = new Date(dpView.y, dpView.m + delta, 1);
|
||||
dpView = { y: d.getFullYear(), m: d.getMonth() };
|
||||
const keep = cParseYmd(dpFocusYmd) || d;
|
||||
const last = new Date(dpView.y, dpView.m + 1, 0).getDate();
|
||||
const day = Math.min(keep.getDate(), last);
|
||||
dpFocusYmd = cYmd(new Date(dpView.y, dpView.m, day));
|
||||
renderDatePicker();
|
||||
repositionOpenPop();
|
||||
}
|
||||
|
||||
if (typeof HTMLInputElement !== "undefined" && HTMLInputElement.prototype.showPicker) {
|
||||
const nativeShowPicker = HTMLInputElement.prototype.showPicker;
|
||||
HTMLInputElement.prototype.showPicker = function () {
|
||||
if (this.type === "date" && this.closest("[data-variant-root]")) {
|
||||
openDatePicker(this);
|
||||
return;
|
||||
}
|
||||
return nativeShowPicker.call(this);
|
||||
};
|
||||
}
|
||||
|
||||
document.addEventListener("mousedown", (e) => {
|
||||
const t = e.target;
|
||||
if (menuEl && !menuEl.hidden && menuEl.contains(t)) return;
|
||||
if (dpEl && !dpEl.hidden && dpEl.contains(t)) return;
|
||||
const dateInp = t.closest && t.closest('input[type="date"]');
|
||||
if (dateInp && dateInp.closest("[data-variant-root]")) {
|
||||
if (dateInp.disabled || dateInp.readOnly) return;
|
||||
e.preventDefault();
|
||||
dateInp.focus();
|
||||
openDatePicker(dateInp);
|
||||
return;
|
||||
}
|
||||
const sel = t.closest && t.closest("select");
|
||||
if (sel && nativeSelect(sel) && sel.closest("[data-variant-root]")) {
|
||||
if (sel.disabled) return;
|
||||
e.preventDefault();
|
||||
sel.focus();
|
||||
openSelectMenu(sel);
|
||||
return;
|
||||
}
|
||||
if (popKind) closePops();
|
||||
}, true);
|
||||
|
||||
document.addEventListener("click", (e) => {
|
||||
const t = e.target;
|
||||
if (!dpEl || dpEl.hidden || !dpEl.contains(t)) return;
|
||||
const nav = t.closest("[data-dp-nav]");
|
||||
if (nav) { shiftDpMonth(+nav.dataset.dpNav); return; }
|
||||
if (t.closest("[data-dp-today]")) {
|
||||
const today = cYmd(new Date());
|
||||
const input = popAnchor;
|
||||
const min = input ? parseLimit(input.min) : "";
|
||||
const max = input ? parseLimit(input.max) : "";
|
||||
if (inDateRange(today, min, max)) commitDate(today);
|
||||
return;
|
||||
}
|
||||
const day = t.closest(".jn-dp-day");
|
||||
if (day && !day.disabled) commitDate(day.dataset.ymd);
|
||||
});
|
||||
|
||||
document.addEventListener("click", (e) => {
|
||||
const t = e.target;
|
||||
if (!menuEl || menuEl.hidden || !menuEl.contains(t)) return;
|
||||
const opt = t.closest(".jn-menu-opt");
|
||||
if (opt && !opt.disabled) commitSelect(+opt.dataset.index);
|
||||
});
|
||||
|
||||
/* ---------- 事件委托 ---------- */
|
||||
document.addEventListener("click", (e) => {
|
||||
const t = e.target;
|
||||
@@ -467,7 +773,60 @@ document.addEventListener("input", (e) => {
|
||||
|
||||
document.addEventListener("keydown", (e) => {
|
||||
if (e.key === "Enter" && e.target.matches && e.target.matches("[data-open-detail]")) openDetail(e.target.dataset.openDetail);
|
||||
if (e.key === "Escape") { closeOverlays(); closeModal(); }
|
||||
if (popKind === "menu" && menuEl && !menuEl.hidden) {
|
||||
const opts = $$(".jn-menu-opt:not(:disabled)", menuEl);
|
||||
if (e.key === "Escape") { e.preventDefault(); closePops(); return; }
|
||||
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
||||
e.preventDefault();
|
||||
if (!opts.length) return;
|
||||
const cur = opts.indexOf(document.activeElement);
|
||||
const next = e.key === "ArrowDown"
|
||||
? (cur + 1) % opts.length
|
||||
: (cur <= 0 ? opts.length - 1 : cur - 1);
|
||||
opts[next].focus();
|
||||
return;
|
||||
}
|
||||
if (e.key === "Home" && opts[0]) { e.preventDefault(); opts[0].focus(); return; }
|
||||
if (e.key === "End" && opts.length) { e.preventDefault(); opts[opts.length - 1].focus(); return; }
|
||||
if ((e.key === "Enter" || e.key === " ") && document.activeElement && document.activeElement.classList.contains("jn-menu-opt")) {
|
||||
e.preventDefault();
|
||||
commitSelect(+document.activeElement.dataset.index);
|
||||
return;
|
||||
}
|
||||
if (e.key === "Tab") { closePops(); return; }
|
||||
}
|
||||
if (popKind === "date" && dpEl && !dpEl.hidden) {
|
||||
if (e.key === "Escape") { e.preventDefault(); closePops(); return; }
|
||||
if (e.key === "ArrowLeft") { e.preventDefault(); shiftDpFocus(-1); return; }
|
||||
if (e.key === "ArrowRight") { e.preventDefault(); shiftDpFocus(1); return; }
|
||||
if (e.key === "ArrowUp") { e.preventDefault(); shiftDpFocus(-7); return; }
|
||||
if (e.key === "ArrowDown") { e.preventDefault(); shiftDpFocus(7); return; }
|
||||
if (e.key === "PageUp") { e.preventDefault(); shiftDpMonth(-1); return; }
|
||||
if (e.key === "PageDown") { e.preventDefault(); shiftDpMonth(1); return; }
|
||||
if (e.key === "Home") { e.preventDefault(); shiftDpFocus(-((cParseYmd(dpFocusYmd) || new Date()).getDay())); return; }
|
||||
if (e.key === "End") { e.preventDefault(); shiftDpFocus(6 - ((cParseYmd(dpFocusYmd) || new Date()).getDay())); return; }
|
||||
if (e.key === "Enter" && document.activeElement && document.activeElement.classList.contains("jn-dp-day") && !document.activeElement.disabled) {
|
||||
e.preventDefault();
|
||||
commitDate(document.activeElement.dataset.ymd);
|
||||
return;
|
||||
}
|
||||
}
|
||||
const dateInp = e.target.closest && e.target.closest('input[type="date"]');
|
||||
if (dateInp && !dateInp.disabled && (e.key === "ArrowDown" || e.key === " " || (e.altKey && e.key === "ArrowDown"))) {
|
||||
e.preventDefault();
|
||||
openDatePicker(dateInp);
|
||||
return;
|
||||
}
|
||||
const sel = e.target.closest && e.target.closest("select");
|
||||
if (nativeSelect(sel) && !sel.disabled && (e.key === "ArrowDown" || e.key === "ArrowUp" || e.key === " " || e.key === "Enter")) {
|
||||
e.preventDefault();
|
||||
openSelectMenu(sel);
|
||||
return;
|
||||
}
|
||||
if (e.key === "Escape") {
|
||||
if (closePops()) return;
|
||||
closeOverlays(); closeModal();
|
||||
}
|
||||
});
|
||||
|
||||
/* — 抽屉拖拽关闭(1:1 跟手 + 速度判定 + 边界阻尼) — */
|
||||
|
||||
Reference in New Issue
Block a user