← All proposals

Chat Attachment

Net-new component: one attached item for chat.

Net-new componentOpen in Storybook

proposals/ChatAttachment/HANDOFF.md163 lines · View on GitHub

Handoff: ChatAttachment

Rewritten 2026-11-20 against v2.0.0-beta.21 to the lessons template. Every prop, class and token below was checked against ChatAttachment.tsx, chat-attachment.css and the stories as they are now. Nothing here was checked by eye in a session.

What and why

One attached file or image in a chat, with an optional remove button. Composer has a fieldHeader slot for attached files but PDS had nothing to put in it, and the same item belongs in a sent ChatMessage. PDS FileUpload is a drop zone (a form field), which is a different thing. Built from PDS Tooltip plus the local Icon and IconButton. Figma: Chat Attachment page (the designer's hand-built component set; the Figma name is ChatFileUpload, the code name is ChatAttachment). Context: context.md.

Exploration and decisions

  • Own component, not part of Composer: an attachment also appears in a sent message. Composer's fieldHeader stays the container.
  • Named ChatAttachment, not ChatFileUpload, to avoid confusion with PDS FileUpload.
  • Fixed size: file chips are one width (spacing-9xl) and height (spacing-3xl) with the name clamped to two lines; images are a spacing-3xl square, so rows wrap predictably.
  • Long names are shortened in the string, not with CSS (CSS cannot keep the end of a name over two lines). Over 24 characters it keeps the start and the extension (verylong-filename-exam….md); with no extension, the last 6 characters. The full name is in a visually-hidden span and the short text is aria-hidden.
  • Full name in the PDS Tooltip with the tile as custom trigger (hover and keyboard focus; tap only on error chips so it does not fight the remove button).
  • Remove button: shown on hover (designer's call), on :focus-within, and always on devices that cannot hover. Only rendered when onRemove is set. No tooltip on it (hasTooltip={false}, title={undefined}); the aria-label stays. Its hover and pressed fill sits on an opaque surface so an image does not show through.
  • Error (status='error', first try): critical background, border and text, diamondExclamation icon; a failed image has no thumbnail, just the image icon in critical color. status, not a boolean, so an uploading value can join it. The chip does not announce its own error (one live message is owned by the screen, for example Composer's helper message).
  • Type uses the semantic pds-copy-2xs class; colors are semantic tokens.

Full list and reasons: decisions.md. Its older entries about a role='alert' span, a dimmed image with a badge, and "first 17 and last 6" are superseded by later entries (a note at the bottom of that file says so); the code matches the later entries.

API

ChatAttachment (extends div props except children; they are spread onto the Tooltip, which puts them on its root div, checked in Tooltip.tsx at beta.21):

Prop Type Default Purpose
className string none Additional class names (on the Tooltip root).
errorMessage string none Why it failed (for example "Upload failed"); in the tooltip and read by screen readers. Used with status='error'.
fileName string none (required) Name of the file. Full name in the tooltip and for screen readers; the visible text is shortened when long.
fileType 'file' | 'image' 'file' image shows a square thumbnail (or an image icon without previewUrl); file shows an icon and the name.
onRemove () => void none Called when the remove button is pressed. The button only renders when this is set.
previewUrl string none Thumbnail URL. Only used when fileType is image and the status is not error.
removeLabel string none Accessible label of the remove button, for example "Remove report.md". TSDoc says "Required when onRemove is set", but the type is optional; the code falls back to ''.
status 'default' | 'error' 'default' error marks the attachment as failed.

Exported types: ChatAttachmentFileType, ChatAttachmentStatus, ChatAttachmentProps.

Variants and states: file and image; with and without a preview; default; hover or focus (remove button visible); error (file and image); long name. Stories: Default, Image.

Story-only helpers (the engineer drops these, L9): the State wrapper and the class chat-attachment-story--hover (chat-attachment-story.css), which holds the hover-only remove button open so the state shows without a pointer; the caption labels; SAMPLE_IMAGE from _story-helpers; the LONG_NAME sample.

Tokens used

From chat-attachment.css as it is now:

  • --pds-border-radius-input
  • --pds-border-width-default
  • --pds-color-border-default
  • --pds-color-foreground-default-secondary
  • --pds-color-status-critical-background
  • --pds-color-status-critical-border
  • --pds-color-status-critical-foreground
  • --pds-color-surface-default
  • --pds-color-surface-default-secondary
  • --pds-spacing-2xs
  • --pds-spacing-3xl
  • --pds-spacing-9xl
  • --pds-spacing-xs

It also reads --icon-button-background-hover, a variable set by .pds-icon-button (it exists in the package icon-button.css at beta.21), so the remove button's hover tint follows the IconButton. The check tool also lists --pds-spacing-l, --pds-spacing-xl, --pds-typography-ff-default and --pds-typography-size-xs; those come from chat-attachment-story.css (story layout and captions only), not the component.

Impact

From impact.md: no existing PDS component is changed and no --pds-* token is redefined. One opt-in addition: a hover and pressed rule on .pds-icon-button scoped to .pds-chat-attachment__remove, so existing IconButtons are unaffected. The generated report says no other proposal imports ChatAttachment, but Composer (story, in fieldHeader) and ChatWithAgent (story) use it; they only use it in stories, so nothing has to port with it.

Reused vs net-new

  • Reused: PDS Tooltip (with customTrigger, disableTapTrigger), local Icon (file, image, diamondExclamation) and local IconButton (xmark, xs, hasTooltip), the pds-copy-2xs and visually-hidden classes.
  • Net-new: .pds-chat-attachment (__icon, __image, __item, __item--error, __item--image, __name, __remove); all props. No custom CSS variables, no raw values kept. Details in custom.md.

Accessibility

Nothing here was run: the a11y panel has not been run, and light and dark were not checked by eye. What the code does:

  • The full file name is always in a visually-hidden span; the shortened visible text is aria-hidden. A thumbnail has alt set to the file name. Do not announce the name twice: the aria-hidden short text and the hidden full name exist for that reason.
  • The error reason is visually-hidden plain text placed before the icon and the name (no role='alert'), read when the user reaches the chip; the screen owns the single live announcement.
  • Remove is a real button with an aria-label from removeLabel. It is revealed on hover, on :focus-within (keyboard) and always on touch (@media (hover: none)), so it is keyboard and touch operable. It is at opacity: 0 (not removed) when hidden, so it stays in the tab order. The tooltip opens on focus, which lands on the remove button inside the trigger.
  • The chip itself is not focusable when there is no onRemove, so the tooltip with the full name is then hover-only for keyboard users; the full name is still in the DOM text.
  • If onRemove is set and removeLabel is missing, the button gets aria-label='' and is unlabelled. See "Expect to change".

Decisions and open questions

Each carries a recommended answer (a recommendation, not a decision; the designer or engineer decides).

  • Dependencies: Icon and IconButton are marked ready for dev, so they can port first. The PDS Tooltip is already in the package. No dependency on an unready proposal. (Recommendation: port Icon and IconButton first, as listed.)
  • Name ChatAttachment (Figma says ChatFileUpload). Recommendation: keep ChatAttachment; FileUpload already exists in the package.
  • Image without a preview: built as "no preview"; is it really "loading"? Recommendation: keep "no preview" until an uploading status exists.
  • Error: first try only. Is the reason shown on the chip, is retry needed (onRetry), should Remove always show on an error, is an errorType needed? An uploading status is not built. Recommendation: ship error as built, add onRetry, errorType and uploading only when a screen needs them.
  • Name shortening counts characters (24, extension kept), not pixels, so it can fit slightly more or less in other fonts. Recommendation: keep; it is the only way to keep the extension over two lines.
  • Extra props go to the Tooltip root div, not the tile. Checked: Tooltip spreads ...props onto its root div (Tooltip.tsx, root element). Recommendation: keep, and say so in the TSDoc.
  • A chip in Composer's fieldHeader: see Footprint.

Extension or new component

New component. It is not an extension of a PDS component: FileUpload (inputs/FileUpload) is a form field with a drop zone and an input, not an item; the package has no attachment or file-chip component. The closest existing piece is Tag (badges/Tag), which has isRemovable, onRemove, removeLabel and truncationLength. It was not extended because it is a single-line colored pill with no thumbnail, no fixed-size tile, no error state and no tooltip with the full name. (Recommendation: new component. The engineer decides if a Tag variant is wanted instead; not verified how it would look.)

Footprint

  • The remove button is drawn outside the tile: it is absolutely positioned at -spacing-2xs (8px) on the top and inline-end, so 8px of it overhangs the top and end edges of the tile. It is opacity: 0 until hover, focus-within, or a device that cannot hover, but it still occupies that space and is focusable.
  • The overhang does not take layout space. A parent could clip it with overflow: hidden, or put a neighbor closer than 8px so the button overlaps it. In Composer, .pds-composer__field has overflow: hidden (composer.css), the field header has gap: spacing-2xs (8px, equal to the overhang) and padding spacing-xs (10px) or spacing-s (12px) on the m size, so by those values the button stays inside the field. Computed from the CSS, not checked by eye; the compact variant (header above the row) was not checked.
  • The tile is inline-flex through the Tooltip root (.pds-tooltip), has a fixed size (160 x 40px for a file, 40px square for an image) and never grows, so a parent that sizes by content gets a predictable box. The root has no styles of its own (.pds-chat-attachment has no rule).
  • The tooltip itself is portaled to the body, so a clipping parent does not cut it.

Dark mode and per-size values

Single size: there is no size prop, and the CSS has no per-theme override. Every color is a semantic token that the theme files redefine, so dark follows from the tokens (values from variables.light.css and variables.dark.css; how they look is not checked).

Part Value Light Dark
File tile size spacing-9xl x spacing-3xl (160 x 40px), padding 0 spacing-xs same same
Image tile size spacing-3xl square (40px), no padding same same
Gap (icon to name) spacing-2xs (8px) same same
Icon size s same same
Remove button IconButton xs (spacing-button-height-xs, 28px), offset -8px same same
Tile background surface-default-secondary oklch(0.9731 0 0) oklch(0.2520 0 0)
Tile border border-default, border-width-default oklch(0.925 0 0) oklch(0.345 0.005 258)
Text and icon foreground-default-secondary oklch(0.4778 0.0020 247.87) oklch(0.8452 0 0)
Error background status-critical-background oklch(0.9629 0.0152 22.40) oklch(0.2550 0.0814 25.05)
Error border status-critical-border oklch(0.5338 0.1771 25.54) oklch(0.5954 0.1582 23.19)
Error text and icon status-critical-foreground oklch(0.4501 0.1581 26.35) oklch(0.8022 0.0731 18.80)
Remove button surface surface-default (opaque), border-default, round oklch(1.0000 0 0) oklch(0.2178 0 0)

Contrast of text on the tile in both themes: not checked.

Expect to change

Each choice below breaks, or may break, a toolkit convention. The answer in italics is a recommendation.

  1. removeLabel is optional with an empty-string fallback (L2, L3). Code: ariaLabel={removeLabel ?? ''}; TSDoc says required; no dev warning. A union type that makes it required with onRemove was floated in the previous handoff. Recommendation: keep the type flat and optional, add a [ChatAttachment] warning under process.env.NODE_ENV !== 'production' when onRemove is set without removeLabel (as Button does). No union type.
  2. Screen-reader text is spread over three props (L3). fileName (hidden full name and alt), errorMessage (hidden reason) and removeLabel are all top-level and translatable, which is the convention. The accessible reason and the tooltip share errorMessage. Recommendation: keep; note in TSDoc what each one announces.
  3. status string union with one other value (L2). 'default' | 'error' instead of isError. Chosen so uploading can join. Recommendation: if the engineer prefers a boolean, isError is fine; the uploading value is not built and has no design.
  4. fileType string union (L2). 'file' | 'image' could be inferred from previewUrl, and Composer's story does infer it (file.previewUrl ? 'image' : 'file'). Recommendation: keep fileType, because an image without a preview still needs the image icon.
  5. Hover-only remove button (designer's call). Shown on hover, focus-within and touch. A toolkit convention may want the remove button always visible. Recommendation: keep; the focus and touch fallbacks cover operability. Confirm by hand with a keyboard and a touch device (not checked).
  6. Name shortening in JS with magic numbers (MAX_NAME_LENGTH 24, TAIL_LENGTH 6). Not a prop. Recommendation: keep as module constants; do not expose knobs (L11).
  7. No size or padding prop (L11). Fixed on purpose. Recommendation: keep it that way.
  8. Local mergeClasses, title={undefined} and hasTooltip={false}. The package IconButton at beta.21 sets title to the aria-label when hasTooltip is false and then spreads ...props, so title={undefined} is still needed to remove the native title. Recommendation: keep both props on the remove button.

Target-version check

Checked in .pds-reference/src at v2.0.0-beta.21 (and CHANGELOG.mdx). The changelog has no entry for a chat attachment.

Item In beta.21? Notes
A chat attachment or file chip component no none in src/components; FileUpload is a form field, Tag is a pill
Tooltip with customTrigger and disableTapTrigger yes overlays/Tooltip/Tooltip.tsx
IconButton size='xs', hasTooltip, ariaLabel yes buttons/IconButton; sizes there are xs, s, m (the local 2xs is not used here)
Icons file, image, diamondExclamation, xmark yes icons/Icon/generated-icon-data.ts
Classes pds-copy-2xs, visually-hidden yes typography styles and foundations/a11y.css
Tokens (spacing 2xs, xs, 3xl, 9xl; critical status; surface, border, foreground) yes pds-design-tokens light and dark files
mergeClasses util yes in source @libs/components/utils, used by Tooltip.tsx; the published package does not export it
--icon-button-background-hover variable yes icon-button.css

Not verified: that the local Icon and IconButton wrappers add nothing this component relies on beyond the items above.

Port notes

Would live in src/components/ (a chat or conversation category folder, for example next to the other chat proposals; generator npm run generate:component). Not yet matching v2: the local mergeClasses stand-in (use @libs/components/utils); the local Icon and IconButton wrappers (use the ported ones); title={undefined} and hasTooltip={false} on IconButton (see Expect to change 8); pds-copy-2xs is !important, so a rule on the same element cannot override size or weight; the -webkit-box two-line clamp on the name. chat-attachment-story.css uses font primitives for the story captions only; it is story scaffolding.

Preview

npm run storybook, story Component Proposals / AI Chat / Chat Attachment. Figma: https://www.figma.com/design/AMGWJbraJoi2PKWnxo29Ah/PDS-Proposals?node-id=291-6953