網站導覽

v2.1.0
表單

行內編輯

平時以文字顯示、可在原處變成欄位的值。

本頁內容

行內編輯讓標題、名稱或儲存格內容平時以文字顯示,需要修改時可在原處切換成欄位。靜止時,它是沿用外層字型樣式的純文字;指標移到上面時,文字周圍會出現淡淡的凹槽,末端顯示鉛筆圖示;按下後,凹槽會變成已取得焦點的欄位,並選取其中的值。預覽和欄位共用同一個格線儲存格、同一種字型、同樣的內距和圓角,因此兩者互換時,文字連一個像素都不會移動。editable 行為負責切換兩者並儲存值。

行內編輯

<div class="max-w(420) mx-auto">  <span class="block mb-xs text-xs fg-text-muted" id="doc-title-label">Title</span>  <h2 class="heading heading-xl">    <span class="editable">      <button type="button" class="editable-preview" id="doc-title-preview" aria-labelledby="doc-title-label doc-title-preview">        Quarterly report<svg class="icon editable-pencil" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">          <path d="M2.6556 12.4849L3.2844 10.1793A0.7 0.7 0 0 1 3.4647 9.8686L10.505 2.8283A0.7 0.7 0 0 1 11.495 2.8283L13.1717 4.505A0.7 0.7 0 0 1 13.1717 5.495L6.1314 12.5353A0.7 0.7 0 0 1 5.8207 12.7156L3.5151 13.3444A0.7 0.7 0 0 1 2.6556 12.4849Z" /><path d="M9.6667 3.6667L12.3333 6.3333" />        </svg>      </button>      <input class="editable-field" value="Quarterly report" aria-labelledby="doc-title-label" required maxlength="80" hidden>    </span>  </h2>  <span class="block mt-xs text-sm fg-text-muted">Last edited by Ada, 2 minutes ago</span></div><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'import PencilIcon from '@master/icons-react/native/16/soft/pencil'export function Example() {  const root = useRef<HTMLDivElement>(null)  useEffect(() => attach(root.current!), [])  return (    <div ref={root} className="max-w(420) mx-auto">      <span className="block mb-xs text-xs fg-text-muted" id="doc-title-label">Title</span>      <h2 className="heading heading-xl">        <span className="editable">          <button type="button" className="editable-preview" id="doc-title-preview" aria-labelledby="doc-title-label doc-title-preview">            Quarterly report<PencilIcon className="icon editable-pencil" />          </button>          <input className="editable-field" defaultValue="Quarterly report" aria-labelledby="doc-title-label" required maxLength={80} hidden />        </span>      </h2>      <span className="block mt-xs text-sm fg-text-muted">Last edited by Ada, 2 minutes ago</span>    </div>  )}
<script>  import { attach } from '@master/ui/behaviors'  import PencilIcon from '@master/icons-svelte/native/16/soft/pencil'</script><div class="max-w(420) mx-auto" {@attach attach}>  <span class="block mb-xs text-xs fg-text-muted" id="doc-title-label">Title</span>  <h2 class="heading heading-xl">    <span class="editable">      <button type="button" class="editable-preview" id="doc-title-preview" aria-labelledby="doc-title-label doc-title-preview">        Quarterly report<PencilIcon class="icon editable-pencil" />      </button>      <input class="editable-field" value="Quarterly report" aria-labelledby="doc-title-label" required maxlength="80" hidden>    </span>  </h2>  <span class="block mt-xs text-sm fg-text-muted">Last edited by Ada, 2 minutes ago</span></div>
<script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'import PencilIcon from '@master/icons-vue/native/16/soft/pencil'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template>  <div ref="root" class="max-w(420) mx-auto">    <span class="block mb-xs text-xs fg-text-muted" id="doc-title-label">Title</span>    <h2 class="heading heading-xl">      <span class="editable">        <button type="button" class="editable-preview" id="doc-title-preview" aria-labelledby="doc-title-label doc-title-preview">          Quarterly report<PencilIcon class="icon editable-pencil" />        </button>        <input class="editable-field" value="Quarterly report" aria-labelledby="doc-title-label" required maxlength="80" hidden>      </span>    </h2>    <span class="block mt-xs text-sm fg-text-muted">Last edited by Ada, 2 minutes ago</span>  </div></template>
按下標題後輸入文字,再按 Enter 儲存,或按 Escape 還原。

#文字的位置

值會與所在的欄對齊:根元素會在兩側各向外延伸 --editable-padding-x,讓凹槽在文字周圍展開,而不是把文字往內推。內距以 em 為單位,因此標題的凹槽相對於標題大小,和儲存格的凹槽相對於儲存格一樣寬裕。

  • 靜止時,預覽是純文字。它是一個按鈕,因此可以取得焦點,而鉛筆(文字後方的 editable-pencil 圖示)會和焦點外框一起出現。
  • 指標移到上面時,文字周圍會出現內凹色調和半像素的輪廓線,鉛筆圖示則在最後一個字後方。在沒有可懸停指標的螢幕上,鉛筆圖示會一直顯示,只是稍淡一些,因為這是文字可以修改的唯一提示。
  • 編輯時,欄位會與周圍表面齊平,並顯示前景色外框與光暈,外觀與取得焦點的輸入欄位相同。預覽隱藏後仍會撐開儲存格,因此下方內容不會移動。瀏覽器若支援 field-sizing: content,欄位會隨值變長而超出預覽的寬度;在其他瀏覽器中,文字會在預覽的寬度內捲動。
  • 等待中。 值正在傳送時,請在根元素上設定 aria-busy="true":預覽會以較淡的文字顯示,且無法按下。

#多行

使用 <textarea> 作為欄位時,就能容納多行的值。在其中按 Enter 會換行,因此要按 Control 或 Command 加 Enter 才會儲存。值為空時,預覽會在 editable-placeholder 中顯示欄位的 placeholder。

多行

<div class="max-w(420) mx-auto text-sm fg-text-body">  <span class="block mb-xs text-xs fg-text-muted" id="doc-summary-label">Summary</span>  <div class="editable w-full">    <button type="button" class="editable-preview" id="doc-summary-preview" aria-labelledby="doc-summary-label doc-summary-preview">      <span class="editable-placeholder">Add a summary for the team</span><svg class="icon editable-pencil" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">        <path d="M2.6556 12.4849L3.2844 10.1793A0.7 0.7 0 0 1 3.4647 9.8686L10.505 2.8283A0.7 0.7 0 0 1 11.495 2.8283L13.1717 4.505A0.7 0.7 0 0 1 13.1717 5.495L6.1314 12.5353A0.7 0.7 0 0 1 5.8207 12.7156L3.5151 13.3444A0.7 0.7 0 0 1 2.6556 12.4849Z" /><path d="M9.6667 3.6667L12.3333 6.3333" />      </svg>    </button>    <textarea class="editable-field" aria-labelledby="doc-summary-label" placeholder="Add a summary for the team" rows="3" hidden></textarea>  </div></div><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'import PencilIcon from '@master/icons-react/native/16/soft/pencil'export function Example() {  const root = useRef<HTMLDivElement>(null)  useEffect(() => attach(root.current!), [])  return (    <div ref={root} className="max-w(420) mx-auto text-sm fg-text-body">      <span className="block mb-xs text-xs fg-text-muted" id="doc-summary-label">Summary</span>      <div className="editable w-full">        <button type="button" className="editable-preview" id="doc-summary-preview" aria-labelledby="doc-summary-label doc-summary-preview">          <span className="editable-placeholder">Add a summary for the team</span><PencilIcon className="icon editable-pencil" />        </button>        <textarea className="editable-field" aria-labelledby="doc-summary-label" placeholder="Add a summary for the team" rows={3} hidden>{``}</textarea>      </div>    </div>  )}
<script>  import { attach } from '@master/ui/behaviors'  import PencilIcon from '@master/icons-svelte/native/16/soft/pencil'</script><div class="max-w(420) mx-auto text-sm fg-text-body" {@attach attach}>  <span class="block mb-xs text-xs fg-text-muted" id="doc-summary-label">Summary</span>  <div class="editable w-full">    <button type="button" class="editable-preview" id="doc-summary-preview" aria-labelledby="doc-summary-label doc-summary-preview">      <span class="editable-placeholder">Add a summary for the team</span><PencilIcon class="icon editable-pencil" />    </button>    <textarea class="editable-field" aria-labelledby="doc-summary-label" placeholder="Add a summary for the team" rows="3" hidden></textarea>  </div></div>
<script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'import PencilIcon from '@master/icons-vue/native/16/soft/pencil'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template>  <div ref="root" class="max-w(420) mx-auto text-sm fg-text-body">    <span class="block mb-xs text-xs fg-text-muted" id="doc-summary-label">Summary</span>    <div class="editable w-full">      <button type="button" class="editable-preview" id="doc-summary-preview" aria-labelledby="doc-summary-label doc-summary-preview">        <span class="editable-placeholder">Add a summary for the team</span><PencilIcon class="icon editable-pencil" />      </button>      <textarea class="editable-field" aria-labelledby="doc-summary-label" placeholder="Add a summary for the team" rows="3" hidden></textarea>    </div>  </div></template>

#行為

editable 接收根元素,也就是帶有 editable 類別的元素,並傳回用來解除行為的函式。

app.js
import { editable } from '@master/ui/behaviors/editable.js'const title = editable(document.querySelector('.editable'))title.edit() // open the fieldtitle.value // the saved value
  • 開啟。 按下預覽時,預覽會隱藏,並顯示帶有已儲存值的欄位,同時選取其中的文字。
  • 儲存。 按 Enter 會儲存,離開欄位時也會儲存。欄位本身的限制條件(required、maxlength、pattern)所拒絕的值不會儲存:按 Enter 時欄位會維持開啟,由瀏覽器說明原因;離開欄位時則會還原已儲存的值。若要讓離開欄位改為取消編輯,請傳入 blur: 'cancel'。
  • 取消。 按 Escape 會還原已儲存的值。
  • 焦點在按 Enter 或 Escape 後會回到預覽;若使用者已將焦點移到別處,則不會移回。
  • 事件。 儲存與原本不同的值時,會將值寫入預覽,並由欄位派送 input 和 change。傳回的函式帶有 value(已儲存的值)和 edit();設定 value 會同時寫入預覽和欄位,但不會派送任何事件。

值接下來要送到哪裡,由頁面決定。值正在傳送時,請在根元素上設定 aria-busy="true"。若伺服器拒絕這個值,請將值設回原本的內容,並在旁邊說明原因;或呼叫 edit() 並將欄位標示為 aria-invalid="true",以顯示危險色邊框,這樣使用者輸入的內容會保留下來,方便修正。

未掛上行為時,預覽是一個沒有作用的按鈕,值仍然可以閱讀。

#適用時機

行內編輯適合閱讀次數遠多於修改次數、而且一次只在原處修改一個的值。若要一起修改多個值並一次儲存,使用由輸入欄位和「儲存」按鈕組成的表單,更能清楚表達儲存的內容和時機。

#鍵盤操作

按鍵動作
Enter, Space在預覽上時,開啟欄位並選取其中的值
Enter在欄位中時,儲存並回到預覽。在 textarea 中,按 Control 或 Command 加 Enter
Escape還原已儲存的值並回到預覽
Tab離開欄位並儲存值;若值不符合欄位的限制條件,則還原已儲存的值

輸入法組字期間,Enter 和 Escape 會交由輸入法處理。

#無障礙

  • 以值的用途為值和欄位命名。範例中由可見的標籤為欄位命名,預覽則透過 aria-labelledby 由標籤和預覽本身命名,因此會被讀成「Title, Quarterly report, button」。
  • 確保沒有腳本時仍能讀到已儲存的值:也就是預覽的文字。
  • 儲存失敗時,請在值的旁邊用文字說明,不要只靠危險色邊框表達。

#React、Svelte 和 Vue

editable 元件會在第一次渲染時寫入初始值並掛上行為,之後由行為更新預覽。元件輸出的值是已儲存的值,而不是正在輸入的內容。用 npx master-ui add editable 將元件複製到專案中。元件的建置與使用方式請參閱 React、Svelte 和 Vue。

ui/editable.tsx
'use client'import { useId, useState, type ComponentProps } from 'react'import { editable } from '@master/ui/behaviors/editable.js'import { useBehavior } from './use-behavior'type Field = Omit<ComponentProps<'input'>, 'value' | 'defaultValue' | 'hidden'> & Omit<ComponentProps<'textarea'>, 'value' | 'defaultValue' | 'hidden'>export interface EditableProps extends Omit<Field, 'children'> {  /** The saved value. */  value?: string  defaultValue?: string  onValueChange?: (value: string) => void  /** What the value is, read with it by assistive technology: the field's name. */  label: string  /** A textarea, for a value of several lines. */  multiline?: boolean  /** The value is on its way: the preview waits. */  busy?: boolean  /** What leaving the field does. `'save'` by default. */  blur?: 'save' | 'cancel'}/** * An editable value. Every prop of a field goes to the field, so `required`, `maxLength` and `placeholder` * are its constraints and what the preview says while the value is empty. *//** The behavior finds its field as it attaches. One line and several are two elements, so it attaches again when `multiline` changes. */const fielded = (root: HTMLElement, options?: { blur?: 'save' | 'cancel', multiline?: boolean }) => editable(root, { blur: options?.blur })export function Editable({ value, defaultValue, onValueChange, label, multiline, busy, blur, disabled, className, ...field }: EditableProps) {  const id = useId()  // The first value is drawn into the first render; after that the behavior writes the preview and the field.  const [first] = useState(() => value ?? defaultValue ?? '')  const ref = useBehavior(fielded, { blur, multiline }, { value, defaultValue, onValueChange })  const shared = { className: 'editable-field', 'aria-label': label, disabled, hidden: true }  return (    <div className={className ? `editable ${className}` : 'editable'} ref={ref} aria-busy={busy || undefined}>      <button type="button" className="editable-preview" id={`${id}preview`} aria-labelledby={`${id}name ${id}preview`} disabled={disabled}>        {first || (field.placeholder ? <span className="editable-placeholder">{field.placeholder}</span> : null)}        <svg className="icon editable-pencil" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M2.6556 12.4849L3.2844 10.1793A0.7 0.7 0 0 1 3.4647 9.8686L10.505 2.8283A0.7 0.7 0 0 1 11.495 2.8283L13.1717 4.505A0.7 0.7 0 0 1 13.1717 5.495L6.1314 12.5353A0.7 0.7 0 0 1 5.8207 12.7156L3.5151 13.3444A0.7 0.7 0 0 1 2.6556 12.4849Z" /><path d="M9.6667 3.6667L12.3333 6.3333" /></svg>      </button>      <span id={`${id}name`} hidden>{label}</span>      {multiline        ? <textarea {...(field as ComponentProps<'textarea'>)} {...shared} defaultValue={first} />        : <input {...(field as ComponentProps<'input'>)} {...shared} defaultValue={first} />}    </div>  )}
ui/Editable.svelte
<script lang="ts" module>  import type { HTMLInputAttributes } from 'svelte/elements'  export interface EditableProps extends Omit<HTMLInputAttributes, 'value' | 'hidden' | 'children'> {    /** The saved value. Bind it, or leave it out. */    value?: string    onValueChange?: (value: string) => void    /** What the value is, read with it by assistive technology: the field's name. */    label: string    /** A textarea, for a value of several lines. */    multiline?: boolean    /** The value is on its way: the preview waits. */    busy?: boolean    /** What leaving the field does. `'save'` by default. */    blur?: 'save' | 'cancel'  }</script><script lang="ts">  import { untrack } from 'svelte'  import { editable } from '@master/ui/behaviors/editable.js'  import { behavior } from './behavior.svelte.js'  let { value = $bindable(), onValueChange, label, multiline, busy, blur, disabled, class: className, ...field }: EditableProps = $props()  const id = $props.id()  // The first value is drawn into the first render; after that the behavior writes the preview and the field.  const first = untrack(() => value) ?? ''  // The behavior finds its field as it attaches. One line and several are two elements, so it attaches again when `multiline` changes.  const fielded = (root: HTMLElement, options?: { blur?: 'save' | 'cancel', multiline?: boolean }) => editable(root, { blur: options?.blur })  const attach = behavior(fielded, () => ({ blur, multiline }), {    value: () => value,    change: (next) => { value = next; onValueChange?.(next) },  })</script><!--  @component  An editable value. Every other prop of a field goes to the field, so `required`, `maxlength` and  `placeholder` are its constraints and what the preview says while the value is empty.--><div class={['editable', className]} aria-busy={busy || undefined} {@attach attach}>  <button type="button" class="editable-preview" id="{id}preview" aria-labelledby="{id}name {id}preview" {disabled}>    {#if first}{first}{:else if field.placeholder}<span class="editable-placeholder">{field.placeholder}</span>{/if}<svg class="icon editable-pencil" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2.6556 12.4849L3.2844 10.1793A0.7 0.7 0 0 1 3.4647 9.8686L10.505 2.8283A0.7 0.7 0 0 1 11.495 2.8283L13.1717 4.505A0.7 0.7 0 0 1 13.1717 5.495L6.1314 12.5353A0.7 0.7 0 0 1 5.8207 12.7156L3.5151 13.3444A0.7 0.7 0 0 1 2.6556 12.4849Z" /><path d="M9.6667 3.6667L12.3333 6.3333" /></svg>  </button>  <span id="{id}name" hidden>{label}</span>  {#if multiline}    <textarea class="editable-field" aria-label={label} {disabled} hidden {...field as Record<string, unknown>} value={first}></textarea>  {:else}    <input class="editable-field" aria-label={label} {disabled} hidden {...field} value={first} />  {/if}</div>
ui/Editable.vue
<script setup lang="ts">import { useAttrs, useId, useTemplateRef } from 'vue'import { editable } from '@master/ui/behaviors/editable.js'import { useBehavior } from './use-behavior'defineOptions({ inheritAttrs: false })const { blur, multiline } = defineProps<{  /** What the value is, read with it by assistive technology: the field's name. */  label: string  /** A textarea, for a value of several lines. */  multiline?: boolean  /** The value is on its way: the preview waits. */  busy?: boolean  /** What leaving the field does. `'save'` by default. */  blur?: 'save' | 'cancel'  disabled?: boolean}>()/** The saved value: `v-model`. */const model = defineModel<string>()/* * An editable value. Every attribute but the class goes to the field, so `required`, `maxlength` and * `placeholder` are its constraints and what the preview says while the value is empty. */const id = useId()const attrs = useAttrs()const field = () => {  const { class: _, ...rest } = attrs  return rest}// The first value is drawn into the first render; after that the behavior writes the preview and the field.const first = model.value ?? ''const placeholder = attrs.placeholder as string | undefinedconst root = useTemplateRef<HTMLDivElement>('root')// The behavior finds its field as it attaches. One line and several are two elements, so it attaches again when `multiline` changes.const fielded = (element: HTMLElement, options?: { blur?: 'save' | 'cancel', multiline?: boolean }) => editable(element, { blur: options?.blur })useBehavior(root, fielded, () => ({ blur, multiline }), model)</script><template>  <div class="editable" :class="$attrs.class" :aria-busy="busy || undefined" ref="root">    <button type="button" class="editable-preview" :id="`${id}-preview`" :aria-labelledby="`${id}-name ${id}-preview`" :disabled="disabled">      <template v-if="first">{{ first }}</template>      <span v-else-if="placeholder" class="editable-placeholder">{{ placeholder }}</span>      <svg class="icon editable-pencil" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2.6556 12.4849L3.2844 10.1793A0.7 0.7 0 0 1 3.4647 9.8686L10.505 2.8283A0.7 0.7 0 0 1 11.495 2.8283L13.1717 4.505A0.7 0.7 0 0 1 13.1717 5.495L6.1314 12.5353A0.7 0.7 0 0 1 5.8207 12.7156L3.5151 13.3444A0.7 0.7 0 0 1 2.6556 12.4849Z" /><path d="M9.6667 3.6667L12.3333 6.3333" /></svg>    </button>    <span :id="`${id}-name`" hidden>{{ label }}</span>    <textarea v-if="multiline" class="editable-field" :aria-label="label" :disabled="disabled" hidden v-bind="field()" :value.attr="first" />    <input v-else class="editable-field" :aria-label="label" :disabled="disabled" hidden v-bind="field()" :value.attr="first">  </div></template>

#類別

類別說明
editable值和它的欄位位於同一個由預覽撐開的儲存格中;根元素會依內距向外延伸,讓文字與所在的欄對齊
editable-preview以按鈕呈現的已儲存值:靜止時是純文字,指標移入時出現淡淡的凹槽和鉛筆圖示。隱藏時仍會撐開儲存格
editable-pencil預覽文字後方的鉛筆圖示,在指標移到上面或取得焦點時顯示,在沒有可懸停指標的地方則一直顯示
editable-field取代預覽的欄位,靜止時隱藏:一個已取得焦點的凹槽,字型、內距和圓角都與預覽相同
editable-placeholder位於預覽內,值為空時顯示的內容:以較淡的文字顯示欄位的 placeholder

#自訂屬性

屬性預設值說明
--editable-padding-x.375em預覽和欄位的行內方向內距,根元素會向外延伸相同距離
--editable-padding-y.125em預覽和欄位的區塊方向內距
--editable-radiusvar(--radius-control-sm)凹槽的圓角

#原始碼

@master/ui/components/editable.css
/* * Editable: a value read as text that becomes a field in place. * The preview and the field stand in one grid cell with the same font, padding and corner, so the text does * not move by a pixel when one replaces the other: the preview stays in the layout while it is hidden and * holds the cell open. At rest the value is plain text, set out from the column by the padding it bleeds * into; under the pointer a faint well appears around it with a pencil at its end, and while editing the * well is a focused field. Its type is whatever it stands in: a heading, a cell, a line of a form. * The editable behavior switches the two and saves; without it the preview is a button that does nothing. */@layer components.ui {  .editable {    --editable-padding-x: .375em;    --editable-padding-y: .125em;    --editable-radius: var(--radius-control-sm);    position: relative;    display: inline-grid;    grid-template: auto / minmax(0, auto);    max-width: calc(100% + var(--editable-padding-x) * 2);    /* The text lines up with the column; the well reaches out around it. */    margin-inline: calc(-1 * var(--editable-padding-x));    vertical-align: baseline;    /*     * While the value is on its way, the preview waits: it reads as pending and takes no press. The pointer     * passes through it to the root, so the root is what shows the progress cursor.     */    &[aria-busy="true"] {      cursor: progress;    }    &[aria-busy="true"] .editable-preview {      color: var(--color-text-muted);      pointer-events: none;      .editable-pencil {        opacity: 0;      }    }  }  /* What the preview and the field share, so that one sits exactly where the other was. */  .editable-preview,  .editable-field {    grid-area: 1 / 1;    box-sizing: border-box;    min-width: 0;    margin: 0;    padding: var(--editable-padding-y) var(--editable-padding-x);    border: 0;    border-radius: calc(var(--editable-radius) * var(--corner-scale));    corner-shape: var(--corner-shape);    font: inherit;    font-feature-settings: inherit;    letter-spacing: inherit;    text-align: start;    text-transform: inherit;  }  .editable-preview {    position: relative;    display: block;    background: transparent;    color: inherit;    white-space: pre-wrap;    overflow-wrap: anywhere;    appearance: none;    cursor: text;    -webkit-tap-highlight-color: transparent;    transition-property: background-color, box-shadow;    transition-duration: var(--duration-quick);    transition-timing-function: var(--easing-glide);    /* The pencil: it follows the last word, so it says what the press will do where the eye already is. */    .editable-pencil {      display: inline-block;      width: .8125em;      height: .8125em;      margin-inline-start: .375em;      color: var(--color-text-muted);      vertical-align: -.0625em;      opacity: 0;      transition: opacity var(--duration-quick) var(--easing-glide);    }    @media (hover: hover) {      &:hover:not(:disabled) {        background: var(--color-surface-inset);        box-shadow: inset 0 0 0 .5px var(--color-line-contour);        .editable-pencil {          opacity: 1;        }      }    }    /* Without a pointer that hovers, the pencil is always there: the only sign the text can be changed. */    @media (hover: none) {      &:not(:disabled) .editable-pencil {        opacity: .7;      }    }    &:focus-visible {      @apply --focus-ring;      outline-offset: 0;      .editable-pencil {        opacity: 1;      }    }    &:active:not(:disabled) {      background: var(--color-surface-inset-hover);    }    &:disabled {      cursor: default;    }    /* Hidden, it still holds the cell open, so the field takes its place and nothing below moves. */    &[hidden] {      display: block;      visibility: hidden;    }    /* A touch target reaches 44px tall without moving the text. */    @media (pointer: coarse) {      &::before {        @apply --touch-target-block;      }    }    @media (forced-colors: active) {      .editable-pencil {        color: ButtonText;      }      /* Heavier than the focus ring, so it steps aside on a focused preview instead of thinning its ring. */      @media (hover: hover) {        &:hover:not(:disabled, :focus-visible) {          outline: 1px solid ButtonText;        }      }    }  }  /* The field: a well risen to the sheet with one ink contour and a halo, as a focused input is. */  .editable-field {    display: block;    width: 100%;    outline: none;    background: var(--color-surface-raised);    color: inherit;    box-shadow: inset 0 0 0 .5px var(--color-line-mark), 0 0 0 .5px var(--color-line-mark), 0 0 0 3.5px var(--color-focus-halo);    caret-color: var(--color-text-strong);    resize: none;    appearance: none;    &::placeholder {      color: var(--color-text-muted);      opacity: 1;    }    /* Where the field can size itself, it grows past the preview as the value does. */    @supports (field-sizing: content) {      field-sizing: content;      min-width: 100%;    }    &:is([aria-invalid="true"], :user-invalid) {      box-shadow: inset 0 0 0 .5px var(--color-danger), 0 0 0 .5px var(--color-danger), 0 0 0 3.5px color-mix(in oklab, var(--color-danger) 15%, transparent);    }    &[hidden] {      display: none;    }    @media (forced-colors: active) {      outline: 2px solid Highlight;      outline-offset: -2px;      /* The danger edge is a shadow, which forced colors drop: the outline says it instead. */      &:is([aria-invalid="true"], :user-invalid) {        outline-color: Mark;      }    }  }  /* What the preview says while the value is empty: the field's placeholder, in the muted ink. */  .editable-placeholder {    color: var(--color-text-muted);  }}