Design Systems and Component Libraries Questions
Building and scaling reusable design foundations: component architecture, design tokens, pattern libraries, versioning, governance, and adoption across teams. Covers ensuring visual and behavioral consistency, evolving a system without breaking consumers, and the tooling and cross-functional alignment that keep a design system healthy at scale.
You are given a dashboard card that contains an avatar, a title, metadata tags, three action buttons, and a small sparkline chart. Break this UI into reusable components for a design system. For each component, list responsibilities, public API (props/slots), state considerations, and how you would compose them to form the card.
Sample Answer
Decompose by identifying the repeating visual groups in the mockup first, header row (avatar, title, overflow), tag row, and footer (actions, chart), then map each group to a component with a narrow API, and let a thin CardWrapper own only layout and selection state, not the content components' internals.
Component breakdown
flowchart TD
C[DashboardCard] --> AV[Avatar]
C --> TB[TitleBlock]
C --> MT[MetadataTags]
C --> AG[ActionGroup]
C --> SP[Sparkline]
AG --> A1[3 action buttons]
| Component | Responsibilities | Public API | State |
|---|---|---|---|
Avatar | Render image/initials fallback, optional status dot | { src, alt, size, status? } | Stateless (internal onError fallback to initials) |
TitleBlock | Primary title, optional subtitle, truncation | { title, subtitle?, truncate? } | Local truncation/tooltip-on-overflow state only |
MetadataTags | Render 0..n tags, collapse overflow | { items: { label, tone? }[], maxVisible } | Expanded/collapsed for overflow |
ActionGroup | Render N action buttons or overflow menu | { actions: { id, label, icon?, onSelect }[] } | Which action is focused/pressed |
Sparkline | Compact trend chart, hover tooltip | { data: number[], width, height, ariaLabel } | Hovered data-point index |
DashboardCard (composition) | Layout, selection state, click region | { avatar, title, tags, actions, chartData, selectable? } | Selected/hovered/focused |
Worked example: the decomposition process
Reading the mockup top to bottom: the avatar, title, and an overflow affordance sit on one row (that's Avatar + TitleBlock, with the card itself deciding layout, not a new component). Tags form a second, clearly repeating row across cards, a natural MetadataTags unit. Three action buttons and the sparkline share the footer but are functionally unrelated, actions trigger commands, the chart displays data, so they become two separate components (ActionGroup, Sparkline) composed side by side by DashboardCard, rather than one "CardFooter" component that would force unrelated concerns to share a single API. Keeping Sparkline as its own component with a plain data: number[] prop (no data-fetching of its own) is what lets it be reused later in a non-card context, like a table row or a detail page, without the card's layout assumptions coming along for the ride.
Trade-offs and pitfalls
Giving Sparkline its own data-fetching hook tied to this dashboard's specific API endpoint, instead of a plain data prop, is a common shortcut that saves a few lines here and makes the component unusable anywhere the data doesn't arrive the same way. Hardcoding ActionGroup to exactly three buttons (matching today's mockup) instead of accepting an actions array breaks the first time a product needs a fourth action or wants to collapse extras into an overflow menu, forcing an API change that a slightly more general design would have avoided for free. And merging the footer into one component because "it's visually one row" optimizes for the current layout at the cost of reusing actions or the chart independently later.
Explain visual regression testing and how it fits into a design system workflow. Describe the difference between pixel-perfect baselines, tolerant diffs (thresholds), and story-based visual tests (Storybook integration). Include a short plan for integrating visual tests into CI for pull requests.
Sample Answer
Direct answer
Visual regression testing renders a component, captures a screenshot, and compares it against a stored baseline to catch unintended visual changes that unit tests cannot see, like a spacing shift or a color that silently drifted. In a design system it runs against the component library's Storybook so every documented state has a canonical reference image, and a pull request that changes a screenshot beyond a set threshold is flagged for human review before merge.
Structured elaboration
Three ways to compare images
| Approach | How it compares | Good for | Weakness |
|---|---|---|---|
| Pixel-perfect baseline | Exact image match, zero tolerance | Critical, rarely-changing components (brand logo, icon set) | Brittle: fails on harmless anti-aliasing or font-rendering differences between machines |
| Tolerant diff (threshold) | Allows a percentage or per-pixel tolerance before flagging | Most components; the practical default | Setting the threshold too loose hides real regressions; too tight recreates the pixel-perfect problem |
| Story-based visual test | Each Storybook story (a specific prop/state combination) is its own snapshot | Design systems specifically, since stories already document every intended state | Only as good as story coverage; an untested state has no baseline to regress against |
Story-based testing is the natural fit for a design system because the stories already exist as documentation; visual regression reuses that same artifact as a test fixture instead of requiring a separate test-authoring effort.
CI plan for pull requests
- On PR, build Storybook and generate snapshots for stories touched by the diff.
- Compare against the approved baseline; a first-time story has no baseline and is captured as the initial one.
- If any diff exceeds the threshold, fail the check and attach the visual diff image to the PR for review.
- A reviewer either requests a fix (unintended regression) or approves the new image as the baseline (intentional design change).
- Run a full sweep of every story, not just the diff's stories, on a nightly schedule to catch regressions that a narrow PR-time run would miss (for example a shared token change affecting components outside the PR's direct diff).
Worked example
A Card component's default padding is changed from 16px to 12px as part of an unrelated spacing-scale update elsewhere in the system. The Card story was not touched directly in that PR, so a PR-scoped visual check (comparing only stories in the diff) would miss it; the nightly full sweep catches the Card snapshot's diff, flags it, and a reviewer confirms whether the padding change was intended for Card too or is an unintended side effect of the token change.
Trade-offs and pitfalls
- The most common pitfall is noise from things that are not real regressions: font anti-aliasing differences between CI and a developer's machine, animations captured mid-frame, or dynamic content like a live timestamp. Run visual tests only in CI (not locally, to avoid font mismatch), disable animations globally in the test environment, and freeze or mock dynamic data in stories used for snapshots.
- A tolerant-diff threshold set too loose to reduce noise will also hide small but real regressions, like a 2px alignment shift; tune the threshold empirically rather than raising it reflexively every time a false positive appears.
- Letting a reviewer casually "approve" a new baseline without checking whether the change was actually intended turns visual regression testing into a rubber stamp; require the approval to reference the PR's stated intent, not just click accept to unblock a merge.
- Named tools commonly used for this workflow: Storybook to define and render deterministic states, and Chromatic or Percy to manage baselines, thresholds, and the PR review UI on top of it.
A product team requests a new component that is visually similar to an existing component but differs in spacing and interaction details. Describe how you would evaluate whether to extend the existing component, add a variant, or create a new component. Include design, API, maintenance, and documentation considerations and how you would document the decision.
Sample Answer
Direct answer
Default to extending the existing component with a variant when the two controls share the same DOM semantics and interaction model and the difference can be expressed as a small, enumerable prop; only fork a brand-new component when the interaction model, accessibility semantics, or required props genuinely diverge. Deciding on visual similarity alone is the most common way this goes wrong.
Structured elaboration
| Question | Points toward variant | Points toward new component |
|---|---|---|
| Same DOM element / ARIA role? | Yes | No |
| Same keyboard and focus behavior? | Yes | No |
| Can the difference be expressed as an enum/boolean prop without conditional branching explosion? | Yes | No, would need many mutually-exclusive props |
| Reused across many surfaces? | Yes, worth investing in a shared API | Rare, one-off use case |
| Independent lifecycle expected (one changes without affecting the other)? | No | Yes |
Design considerations: does the visual delta (spacing, elevation, density) map cleanly onto an existing token axis, or does it require a genuinely new visual language?
API considerations: an additive prop like size="compact" | "default" keeps one component, one test suite, one accessibility audit surface. A prop that would require the component to conditionally render entirely different markup depending on its value is a sign the two things aren't really the same component.
Maintenance considerations: one component with variants means a single place to fix bugs and a single a11y audit, but risks becoming a "god component" if variants keep accumulating. A new component isolates blast radius but duplicates logic and needs its own audit and test coverage.
Documenting the decision: write a short ADR-style note (context, options considered, decision, consequences) in the design-system repo, add the new variant or component to the docs/Storybook with all states, and log a changelog entry so downstream teams know what changed and why.
Worked example
Request: a "compact" button, 32px tall with 4px padding, for a dense data-table toolbar, versus the existing 40px/8px-padding default Button. Walking the checklist: same DOM element and ARIA role (yes), same click/keyboard/focus behavior (yes), the delta is expressible as size="compact" | "default" with no conditional markup (yes), and the compact size is likely to be reused anywhere tables or toolbars appear (yes). Decision: add a size variant to the existing Button, not a new component.
Contrast case: a request that looks visually similar (same rounded-rect shape, same color) but needs multi-select toggle behavior with role="checkbox" semantics and a different keyboard model (Space to toggle, no navigation between options) is not a variant of Button even though it looks like one at a glance. The interaction and accessibility semantics diverge, so a new component (ToggleButton) is justified despite the visual resemblance.
Trade-offs & pitfalls
Unchecked variant growth leads to a component with a dozen-plus boolean/enum props and untested prop combinations, which is a real maintenance and QA burden. Premature forking into a new component leads to duplicated bug fixes and, worse, divergent accessibility behavior between two things a user experiences as "the same control." The recurring pitfall is deciding from a screenshot instead of from the interaction model: "looks the same" and "behaves the same" are different questions, and only the second one should drive the variant-vs-new-component call.
API design exercise: For a complex data-table component used across the product, design a public API (props/events/slots) that allows column definitions, sorting, virtualization, row actions, and custom cell rendering while preserving performance and accessibility. Describe default behaviors, extensibility points, and how you would document usage patterns and constraints.
Sample Answer
Direct answer
Design the public API around a declarative column schema plus a small set of slot-based extension points (custom cell and header renderers), default sensible behaviors (sortable, keyboard-navigable, virtualized past a size threshold), and explicit typed props for anything stateful (selection, sort) - so consumers never need to reach into internal implementation details to get default behavior right.
Structured elaboration
Column schema is the backbone
Each column is a plain object (key, label, sortable, render) rather than requiring JSX children per column. That keeps the common case - define columns, pass data - declarative and serializable (column config could even come from a backend), while render remains the escape hatch for fully custom cells.
Row selection is a first-class typed prop, not something consumers build on top of row clicks themselves: selectable: "none" | "single" | "multi" plus selectedRowKeys/onSelectionChange, controlled the same way as any other stateful prop in the system (selectedRowKeys present means controlled).
Extensibility via named slots (HeaderSlot, ColumnSlot, CellSlot) for the cases a plain column object can't express - a bulk-action toolbar in the header, a fully custom column header with a sort icon. Slots are additive on top of the column schema, not a replacement for it.
Virtualization is a default behavior above a row-count threshold, not something every consumer has to opt into by hand, but it stays configurable (virtualization={{ rowHeight, overscan }}) for consumers who need to tune it.
Encapsulation
The component's internal DOM structure, its virtualization implementation, and its row-key-to-index mapping are explicitly not part of the public API. Consumers customize through render, slots, and props - never by reaching into refs to mutate internal markup. This is what lets the internals (for example, swapping the virtualization strategy) change in a minor release without that being a breaking change.
Worked example
interface Column<T> {
key: string;
label: string;
width?: number;
align?: "left" | "right" | "center";
sortable?: boolean;
render?: (row: T) => React.ReactNode;
}
interface DataTableProps<T> {
data: T[];
columns: Column<T>[];
rowKey: (row: T) => string;
selectable?: "none" | "single" | "multi";
selectedRowKeys?: string[]; // controlled
defaultSelectedRowKeys?: string[]; // uncontrolled
onSelectionChange?: (keys: string[]) => void;
sortKey?: string; // controlled sort
sortDirection?: "asc" | "desc";
onSort?: (key: string, direction: "asc" | "desc") => void;
virtualization?: { rowHeight: number; overscan?: number };
density?: "compact" | "comfortable" | "spacious";
}
<DataTable
data={rows}
columns={[
{ key: "name", label: "Name", sortable: true, render: (row) => <UserPill {...row} /> },
{ key: "age", label: "Age", align: "right", sortable: true },
]}
rowKey={(row) => row.id}
selectable="multi"
selectedRowKeys={selectedIds}
onSelectionChange={setSelectedIds}
onSort={(key, dir) => refetchSorted(key, dir)}
virtualization={{ rowHeight: 44, overscan: 5 }}
/>
Key points
renderon aColumn<T>takes the whole row, not just the column's own value, so it can compose multiple fields into one cell.- Selection and sort follow the exact same controlled/uncontrolled contract as every other stateful component in the system, so consumers don't need to learn a new pattern for this component specifically.
rowKeyis required, not optional with an index fallback - an index-based key breaks virtualization and selection correctness the moment rows are re-sorted or re-filtered.
Complexity
Virtualization is the one place real algorithmic reasoning applies. Rendering only the visible window bounds DOM node count to roughly (viewport height / rowHeight) + 2 x overscan, independent of total row count - so rendering cost is O(visible rows), not O(n) total rows, which is the entire point of turning virtualization on for large datasets. Sorting delegated to the consumer via onSort (server-side) costs the table component nothing; client-side sorting is a standard comparison sort over data, O(n log n) per sort action.
Edge cases
- Re-sorting or filtering while rows are virtualized and some are selected:
selectedRowKeysmust reference stable row keys, not indices, or a re-sort silently reassigns selection to the wrong rows - exactly whyrowKeyis required and an index-based fallback is rejected above. - A
renderfunction returning a wide or variable-height cell breaks the fixedrowHeightassumption virtualization depends on - either enforce fixed row height as a documented constraint, or support variable-height virtualization explicitly (meaningfully more complex, worth building only if a real use case needs it). - Empty
dataand emptycolumnsneed explicit empty-state handling (a dedicated slot or a documented default message), not a bare empty table body, both for UX and because screen readers need something to announce.
Trade-offs & pitfalls
- The column-object-plus-slots design is more flexible than pure JSX-children columns, but it's a bigger API surface to design well upfront. A simpler JSX-children API is faster to ship initially but tends to make virtualization and schema-driven features (like exporting the column config to drive a backend query) much harder to retrofit later.
- Defaulting virtualization on above a row-count threshold is convenient but can surprise a consumer relying on DOM queries against off-screen rows. Document the threshold and the fact that off-screen rows aren't in the DOM at all, not just visually hidden.
- The common wrong turn is exposing an internal ref or DOM escape hatch "just in case" a consumer needs something the API doesn't support yet - this is exactly the internal-implementation-detail leak that undermines encapsulation. Once a ref is public, the internals it points to can't change without a breaking release, which defeats the point of keeping virtualization and DOM structure private.
Some visual properties are context-dependent (e.g., card elevation vs modal elevation). How would you model contextual tokens without exploding the token namespace? Propose an approach that supports context composition and keeps tokens maintainable.
Sample Answer
Direct answer
Model context-dependent values as a composition of a small set of intent-based base tokens (surface, overlay) and a small set of context modifiers (card, modal), resolved together at build or render time, rather than creating a separate token for every property-by-context combination. The namespace stays small because contexts are reusable modifiers, not one-off tokens.
Structured elaboration
Why naive per-combination tokens explode
If elevation alone needs a distinct token for every host component (card, modal, dropdown, tooltip, popover), and the system has, say, four elevation levels and six contexts, that's already 24 tokens for one property, and every new context multiplies the count further. The combination is the problem, not the base values.
Two-layer model
- Base semantic tokens: express intent, not context.
elevation.surface(a subtle resting shadow) andelevation.overlay(a strong shadow for content that floats above everything else) are the only two base values most systems actually need. - Context modifiers: a small, named set of scale/offset adjustments.
context.cardmight dampen the base shadow (it's a resting element),context.modalmight amplify it (it needs to visually separate from the whole page). - Composition: a resolver combines base token and modifier at the point of use, rather than a designer or engineer having to remember a bespoke value per context.
Precedence for stacked contexts
When a card renders inside a modal, apply modifiers in a documented, fixed order (innermost first) rather than an ad hoc combination, so a component author never has to guess which modifier wins.
Worked example
Base tokens:
:root {
--elevation-surface-y: 2px;
--elevation-surface-blur: 8px;
--elevation-surface-alpha: 0.12;
--context-card-scale: 0.8;
}
Composition:
.card {
--elev-y: calc(var(--elevation-surface-y) * var(--context-card-scale));
box-shadow: 0 var(--elev-y) var(--elevation-surface-blur) rgba(0, 0, 0, var(--elevation-surface-alpha));
}
The resolved value:
elevation.card.y=elevation.surface.y×context.card.scale=2px×0.8=1.6pxNo card-elevation token was ever authored, it's the composition of one base token and one reusable modifier, and the same context.card modifier applies to any other property (border-radius, opacity) a card variant needs to dampen, without a new token per property.
Trade-offs & pitfalls
Composition adds a layer of indirection: reading .card's final box-shadow value now requires resolving two tokens instead of reading one, which is a real cost for a component author debugging a visual issue without tooling support (a resolver preview in Figma or a browser devtools helper mitigates this, but only if someone builds it). The model also breaks down if teams start inventing new contexts ad hoc instead of reusing the documented set, at that point the namespace explosion just moved from properties to contexts. The right calibration is to keep the context list intentionally small and centrally owned, adding a new context should require the same review a new base token would.
Unlock Full Question Bank
Get access to all Design Systems and Component Libraries interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.