前端前線 2026 年 8 月 22 日

2026-08-22 — WHATWG HTML 三項規範修正:模組對照表清理、command/popover IDL 反射修正、表單控制項置中改用 CSS

primary=https://github.com/whatwg/html/commit/508a037333d8a1806504303aeb489d931fabbef6 primary=https://github.com/whatwg/html/commit/a95983cf5eed71e8984898061e538232a0f56869 primary=https://github.com/whatwg/html/commit/6543b51274ce6e6acb8942967a442339422f6076 primary=https://github.com/w3c/csswg-drafts/issues/14190

WHATWG HTML 清除模組對照表中殘留的 null 語意

WHATWG HTML · 2026-08-21

2026 年 8 月 21 日,WHATWG HTML living standard 收到一次純編輯性修正 508a037,移除「模組對照表」(module map)章節中殘留的 null 參照文字。commit message 說明這是稍早的 7600b24 遺留下來的疏漏,此次修改不影響任何實際行為

修正前,規範文字描述 module map 的值可以是「a module script, null (used to represent a mismatched MIME type), or a list of algorithms」;判斷條件也保留了「is a module script or null」的分支。修正後統一拿掉 null 分支,只保留 module script 與 algorithm list 兩種狀態。

- ...a module script, null (used to represent a mismatched
-   MIME type), or a list of algorithms.
+ ...a module script or a list of algorithms.

這類 null 描述原本對應的是 MIME 類型不符時的中介狀態,但實際演算法早已改用其他方式表達該狀態,規範文字沒有同步跟上,才會留下這處死語意。

原始來源:WHATWG HTML commit 508a037


WHATWG HTML 修正 command / popover 屬性的 IDL 反射對應

WHATWG HTML · 2026-08-21

同日,commit a95983c 修正了兩個較新表單互動 API 的 IDL 定義:HTMLButtonElement.commandForElementPopoverTargetAttributes.popoverTargetElement兩者原本的 [Reflect] 標註都少寫了對應的內容屬性名稱,造成 IDL 與實際 HTML 屬性名稱對不上。

核心改動

Web IDL 的 [Reflect] extended attribute 預設規則是把 IDL 屬性名稱轉小寫後,直接當作對應的 HTML content attribute 名稱。但 commandForElement 轉小寫是 commandforelement,實際內容屬性卻是 commandfor;popoverTargetElement 同理對應到 popovertarget 而非 popovertargetelement。此次修正明確補上參數:

// HTMLButtonElement
[CEReactions] attribute Element? commandForElement;
// [Reflect]  →  [Reflect="commandfor"]

// PopoverTargetAttributes
[CEReactions] attribute Element? popoverTargetElement;
// [Reflect]  →  [Reflect="popovertarget"]

這兩個屬性分別屬於 Invoker Commands API(command / commandfor 屬性)與 Popover API(popovertarget 屬性),都是近期才進入 HTML 規範的互動機制,IDL 反射細節此前未被充分檢查。

原始來源:WHATWG HTML commit a95983c


WHATWG HTML 廢除按鈕「匿名內容框」,改用 CSS align-content 置中表單控制項

WHATWG HTML · 2026-08-12

WHATWG HTML editor emilio 提交的 commit 6543b51 移除了瀏覽器內部用來置中 <button><input><select> 內容的「匿名按鈕內容框」(anonymous button content box),改用標準 CSS 屬性定義置中行為。此變更同時回應了 CSS Working Group issue w3c/csswg-drafts#14190 中關於 text input 的 unsafe center 對齊語意長期未定義的問題。

背景

過去為了讓表單控制項的內容在 block axis 上置中,瀏覽器各自透過內部佈局「魔法」達成,並非依賴一般網頁開發者可見、可覆寫的 CSS box alignment 機制。這使得置中行為缺乏明確規格描述,也連帶讓 text input / textarea 在內容溢位時該如何對齊(是否退回起始對齊)沒有標準答案。

核心改動

規範改用 CSS Box Alignment 的 align-content 屬性,明確定義三類控制項的預設置中方式:

  • 文字輸入框(text input / textarea):align-content: unsafe center
  • 按鈕與檔案選取按鈕(button / file selector button):align-content: center
  • 下拉選單(select):align-content: center

CSS Box Alignment 模組區分 safeunsafe 兩種對齊語意:safe 對齊在內容溢位、可能造成資料裁切遺失時會自動退回 start 對齊;unsafe 則不論是否溢位都強制套用指定對齊方式。文字輸入框採用 unsafe center,代表輸入內容超出可視範圍時仍維持置中裁切,而不會自動改回靠左對齊。

影響範圍

此次修改的 diff 淨變動約 32 行新增、35 行刪除,規模不大但屬於行為定義層級的修正,而非單純文字校對。表單控制項的置中邏輯從「瀏覽器各自實作的內部特例」轉為「開發者可見且可用 CSS 覆寫的標準屬性」,對瀏覽器引擎而言需要調整內部渲染樹的建構方式,對開發者而言則代表自訂表單樣式時的置中行為將有明確規格可循。

原始來源:WHATWG HTML commit 6543b51CSSWG issue #14190


End of article
0
Would love your thoughts, please comment.x
()
x