导航

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 保存,或按 Esc 恢复原值。

#文字的位置

值与所在列的文字对齐:根元素向两侧各外扩 --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' 可让离开输入框改为取消编辑。
  • 取消。 按 Esc 会恢复已保存的值。
  • 焦点在按 Enter 和 Esc 后回到预览;如果用户已将焦点移到别处,则不会移回。
  • 事件。 保存一个不同的值时,脚本会将其写入预览,并从输入框派发 input 和 change。返回的函数带有 value(已保存的值)和 edit();为 value 赋值会同时写入预览和输入框,但不会派发任何事件。

值之后要送往何处由页面决定。值正在提交时,为根元素设置 aria-busy="true"。如果服务器拒绝了这个值,可以将值改回原样并在旁边说明原因,或者调用 edit() 并将输入框标记为 aria-invalid="true",显示危险色轮廓:已输入的内容会保留下来,供读者修改。

没有行为脚本时,预览是一个不执行任何操作的按钮,值仍然可读。

#适用场景

行内编辑适合阅读远多于修改、并且在原位逐个修改的值。如果需要同时修改多个值并一次性保存,使用由输入框和“保存”按钮组成的表单,能更清楚地说明保存了什么、何时保存。

#键盘操作

按键操作
Enter, Space位于预览上时,打开输入框并选中其中的值
Enter位于输入框中时,保存并返回预览;在 textarea 中,使用 Control 或 Command 加 Enter
Escape恢复已保存的值并返回预览
Tab离开输入框并保存值;如果输入框的约束拒绝该值,则恢复已保存的值

输入法处于组字状态时,Enter 和 Esc 由输入法处理。

#无障碍

  • 用值所代表的含义为值和输入框命名。示例中,可见的标签为输入框命名,预览则通过 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);  }}