Rebuild Tansy UI on Base UI with one API and dark mode (v0.3.0)
Every component is rebuilt on @base-ui/react with a single prop API, token-only colours and dark mode, and 28 new components are added. Components - New: Field, FeaturedTextArea, NumberInput, Combobox, CheckboxGroup, Slider, ToggleGroup/Toggle, IconButton, Dialog/Modal, AlertDialog, Drawer/Sheet, Popover, InfoTip, DropdownMenu, Tabs, Breadcrumb, Pagination, Toast (Toaster, useToast), Progress, Meter, Skeleton, CountBadge, Avatar/AvatarGroup, Kbd, Separator, Table - Rewritten: Button, Input, FeaturedInput, TextArea, Select, FeaturedSelect (real ARIA combobox), NativeSelect, Checkbox, Radio, Switch, Tooltip, Accordion, Alert, Spinner, Badge, Card - Removed TextField (use Input) and sonner (use Toast) Foundations - Semantic tokens (surfaces, text, borders, status ramps) in src/styles/tokens.css, with class-based dark mode - Visible focus rings, linked labels/descriptions/errors, alert roles by severity, keyboard support from Base UI - Fixed the Classic Blue ramp; Emerald, Amber and Teal 500 steps now carry white text at AA - Library build (per-component ES modules, types, tokens.css, exports) Quality - Vitest, Testing Library and axe tests for every component (289 tests) - scripts/check-stories.mjs renders every story in Chrome and fails on errors or axe violations, including contrast; all 423 stories pass in light and dark mode and in all seven palettes - Storybook: controls for every prop, open states for every popup, light/dark toolbar, Introduction guides, docs/CONVENTIONS.md BREAKING CHANGE: component props changed across the kit; see CHANGELOG.md.
This commit is contained in:
1 parent
dc5e6ff800
commit
f01de83733
185 files changed
+22542
-5182
No files matched your search
@@ -0,0 +1,94 @@
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { useState } from 'react'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { expectNoA11yViolations } from '../test/a11y'
|
||||
import { NativeSelect } from './NativeSelect'
|
||||
import type { SelectOption } from './select.tokens'
|
||||
|
||||
const currencies: SelectOption[] = [
|
||||
{ value: 'usd', label: 'US Dollar', group: 'Americas' },
|
||||
{ value: 'cad', label: 'Canadian Dollar', group: 'Americas' },
|
||||
{ value: 'eur', label: 'Euro', group: 'Europe' },
|
||||
{ value: 'gbp', label: 'Pound Sterling', group: 'Europe', disabled: true },
|
||||
]
|
||||
|
||||
const plain: SelectOption[] = [
|
||||
{ value: 'eng', label: 'Engineering' },
|
||||
{ value: 'fin', label: 'Finance' },
|
||||
]
|
||||
|
||||
describe('NativeSelect', () => {
|
||||
it('links the label to the select', () => {
|
||||
render(<NativeSelect label="Department" options={plain} />)
|
||||
expect(screen.getByRole('combobox', { name: 'Department' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders groups as optgroups and a placeholder option', () => {
|
||||
render(<NativeSelect label="Currency" placeholder="Choose a currency" options={currencies} />)
|
||||
const select = screen.getByRole('combobox', { name: 'Currency' })
|
||||
expect(select).toHaveValue('')
|
||||
expect(screen.getAllByRole('group').map((g) => g.getAttribute('label'))).toEqual(['Americas', 'Europe'])
|
||||
expect(screen.getByRole('option', { name: 'Pound Sterling' })).toBeDisabled()
|
||||
})
|
||||
|
||||
it('works uncontrolled and fires onValueChange and onChange', async () => {
|
||||
const onValueChange = vi.fn()
|
||||
const onChange = vi.fn()
|
||||
render(<NativeSelect label="Department" options={plain} onValueChange={onValueChange} onChange={onChange} />)
|
||||
const select = screen.getByRole('combobox', { name: 'Department' })
|
||||
expect(select).toHaveValue('eng')
|
||||
await userEvent.selectOptions(select, 'fin')
|
||||
expect(select).toHaveValue('fin')
|
||||
expect(onValueChange).toHaveBeenCalledWith('fin')
|
||||
expect(onChange).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('works controlled', async () => {
|
||||
function Controlled() {
|
||||
const [value, setValue] = useState('fin')
|
||||
return (
|
||||
<>
|
||||
<NativeSelect label="Department" options={plain} value={value} onValueChange={setValue} />
|
||||
<p data-testid="value">{value}</p>
|
||||
</>
|
||||
)
|
||||
}
|
||||
render(<Controlled />)
|
||||
const select = screen.getByRole('combobox', { name: 'Department' })
|
||||
expect(select).toHaveValue('fin')
|
||||
await userEvent.selectOptions(select, 'eng')
|
||||
expect(screen.getByTestId('value')).toHaveTextContent('eng')
|
||||
expect(select).toHaveValue('eng')
|
||||
})
|
||||
|
||||
it('announces the description, and the error when invalid', () => {
|
||||
const { rerender } = render(<NativeSelect label="Department" description="Where they report." options={plain} />)
|
||||
expect(screen.getByRole('combobox')).toHaveAccessibleDescription('Where they report.')
|
||||
rerender(<NativeSelect label="Department" description="Where they report." error="Choose one." options={plain} />)
|
||||
expect(screen.getByRole('combobox')).toHaveAttribute('aria-invalid', 'true')
|
||||
expect(screen.getByRole('combobox')).toHaveAccessibleDescription('Choose one.')
|
||||
})
|
||||
|
||||
it('passes required, disabled and name to the select', () => {
|
||||
render(<NativeSelect label="Department" name="department" required disabled options={plain} />)
|
||||
const select = screen.getByRole('combobox', { name: /Department/ })
|
||||
expect(select).toBeRequired()
|
||||
expect(select).toBeDisabled()
|
||||
expect(select).toHaveAttribute('name', 'department')
|
||||
})
|
||||
|
||||
it('is disabled and busy while loading', () => {
|
||||
render(<NativeSelect label="Department" loading options={plain} />)
|
||||
const select = screen.getByRole('combobox', { name: 'Department' })
|
||||
expect(select).toBeDisabled()
|
||||
expect(select).toHaveAttribute('aria-busy', 'true')
|
||||
})
|
||||
|
||||
it('has no axe violations', async () => {
|
||||
const { container } = render(
|
||||
<NativeSelect label="Currency" description="Used on payslips." placeholder="Choose" required options={currencies} />,
|
||||
)
|
||||
await expectNoA11yViolations(container)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user