Skip to content

Commit 25b305b

Browse files
authored
docs: Update React Aria example styling (#9049)
* Add isPressed to table column header render props * docs: Update React Aria example styling * fix * lint * Fixes and improvements * fix ts and test * fix disclosure * more fixes
1 parent 4b8c6eb commit 25b305b

File tree

174 files changed

+4063
-2527
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

174 files changed

+4063
-2527
lines changed

packages/@react-aria/disclosure/src/useDisclosure.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export function useDisclosure(props: AriaDisclosureProps, state: DisclosureState
7373
if (raf.current) {
7474
cancelAnimationFrame(raf.current);
7575
}
76-
if (ref.current && !isDisabled && !isSSR) {
76+
if (ref.current && !isSSR) {
7777
let panel = ref.current;
7878

7979
if (isExpandedRef.current == null || typeof panel.getAnimations !== 'function') {
@@ -155,7 +155,7 @@ export function useDisclosure(props: AriaDisclosureProps, state: DisclosureState
155155
role: 'group',
156156
'aria-labelledby': triggerId,
157157
'aria-hidden': !state.isExpanded,
158-
hidden: !state.isExpanded || undefined
158+
hidden: isSSR ? !state.isExpanded : undefined
159159
}
160160
};
161161
}

packages/@react-aria/disclosure/test/useDisclosure.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ describe('useDisclosure', () => {
9191
});
9292

9393
it('should keep panel hidden when toggling disabled state', () => {
94-
let {result, rerender} = renderHook(({isDisabled}: {isDisabled: boolean}) => {
94+
let {rerender} = renderHook(({isDisabled}: {isDisabled: boolean}) => {
9595
let state = useDisclosureState({});
9696
return useDisclosure({isDisabled}, state, ref);
9797
}, {initialProps: {isDisabled: false}});
@@ -100,13 +100,13 @@ describe('useDisclosure', () => {
100100
rerender({isDisabled: true});
101101
});
102102

103-
expect(result.current.panelProps.hidden).toBe(true);
103+
expect(ref.current.hidden).toBe(true);
104104

105105
act(() => {
106106
rerender({isDisabled: false});
107107
});
108108

109-
expect(result.current.panelProps.hidden).toBe(true);
109+
expect(ref.current.hidden).toBe(true);
110110
});
111111

112112
it('should set correct IDs for accessibility', () => {

packages/@react-aria/table/src/useTableColumnHeader.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ export interface AriaTableColumnHeaderProps<T> {
3131

3232
export interface TableColumnHeaderAria {
3333
/** Props for the [column header](https://www.w3.org/TR/wai-aria-1.1/#columnheader) element. */
34-
columnHeaderProps: DOMAttributes
34+
columnHeaderProps: DOMAttributes,
35+
/** Whether the column is currently in a pressed state. */
36+
isPressed: boolean
3537
}
3638

3739
/**
@@ -48,7 +50,7 @@ export function useTableColumnHeader<T>(props: AriaTableColumnHeaderProps<T>, st
4850

4951
let isSelectionCellDisabled = node.props.isSelectionCell && state.selectionManager.selectionMode === 'single';
5052

51-
let {pressProps} = usePress({
53+
let {pressProps, isPressed} = usePress({
5254
isDisabled: !allowsSorting || isSelectionCellDisabled,
5355
onPress() {
5456
state.sort(node.key);
@@ -100,6 +102,7 @@ export function useTableColumnHeader<T>(props: AriaTableColumnHeaderProps<T>, st
100102
id: getColumnHeaderId(state, node.key),
101103
'aria-colspan': node.colSpan && node.colSpan > 1 ? node.colSpan : undefined,
102104
'aria-sort': ariaSort
103-
}
105+
},
106+
isPressed
104107
};
105108
}

packages/dev/docs/pages/react-aria/home/ExampleApp.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import {Button} from 'tailwind-starter/Button';
1515
import {Cell, Column, Row, TableHeader} from 'tailwind-starter/Table';
1616
import {Checkbox} from 'tailwind-starter/Checkbox';
1717
import {CloudSun, Dessert, Droplet, Droplets, FilterIcon, Mail, MoreHorizontal, PencilIcon, PlusIcon, RefreshCw, ShareIcon, SlidersIcon, StarIcon, Sun, SunDim, TrashIcon, Twitter} from 'lucide-react';
18-
import {ColumnProps, Dialog, DialogTrigger, DropZone, Form, Heading, isFileDropItem, Key, MenuTrigger, ModalOverlay, ModalOverlayProps, Modal as RACModal, ResizableTableContainer, Selection, SortDescriptor, SubmenuTrigger, Table, TableBody, Text, ToggleButton, ToggleButtonProps, TooltipTrigger} from 'react-aria-components';
18+
import {ColumnProps, Dialog, DialogTrigger, DropZone, Form, Heading, isFileDropItem, Key, ModalOverlay, ModalOverlayProps, Modal as RACModal, ResizableTableContainer, Selection, SortDescriptor, Table, TableBody, Text, ToggleButton, ToggleButtonProps, TooltipTrigger} from 'react-aria-components';
1919
import {ComboBox, ComboBoxItem} from 'tailwind-starter/ComboBox';
2020
import {DatePicker} from 'tailwind-starter/DatePicker';
2121
import {focusRing} from 'tailwind-starter/utils';
2222
import {getLocalTimeZone, today} from '@internationalized/date';
2323
import {GridList, GridListItem} from 'tailwind-starter/GridList';
24-
import {Menu, MenuItem} from 'tailwind-starter/Menu';
24+
import {Menu, MenuItem, MenuTrigger, SubmenuTrigger} from 'tailwind-starter/Menu';
2525
import {Modal} from 'tailwind-starter/Modal';
2626
import plants, {Plant} from './plants';
2727
import {Popover} from 'tailwind-starter/Popover';
@@ -41,7 +41,7 @@ const allColumns: ColumnProps[] = [
4141
{id: 'cycle', children: 'Cycle', defaultWidth: 120, allowsSorting: true},
4242
{id: 'sunlight', children: 'Sunlight', defaultWidth: 120, allowsSorting: true},
4343
{id: 'watering', children: 'Watering', defaultWidth: 120, allowsSorting: true},
44-
{id: 'actions', children: <VisuallyHidden>Actions</VisuallyHidden>, width: 44, minWidth: 44}
44+
{id: 'actions', children: <VisuallyHidden>Actions</VisuallyHidden>, width: 64, minWidth: 64}
4545
];
4646

4747
let hideOnScroll = document.getElementById('hideOnScroll');
@@ -237,9 +237,9 @@ export function ExampleApp(): React.ReactNode {
237237
<img alt="" src={item.default_image?.thumbnail} className="inline rounded-sm row-span-3 object-contain h-[40px]" />
238238
<span className="truncate capitalize">{item.common_name}</span>
239239
<span className="truncate text-xs text-gray-600 dark:text-zinc-400 col-start-2 row-start-2">{item.scientific_name}</span>
240-
<MenuTrigger>
241-
<Button aria-label="Actions" variant="icon" className="row-span-2 place-self-center"><MoreHorizontal className="w-5 h-5" /></Button>
242-
<Menu placement="bottom end" onAction={action => onAction(item, action)}>
240+
<MenuTrigger placement="bottom end" >
241+
<Button aria-label="Actions" variant="secondary" className="row-span-2 place-self-center"><MoreHorizontal className="w-5 h-5" /></Button>
242+
<Menu onAction={action => onAction(item, action)}>
243243
<MenuItem id="favorite"><StarIcon aria-hidden className="w-4 h-4" /> {item.isFavorite ? 'Unfavorite' : 'Favorite'}</MenuItem>
244244
<MenuItem id="edit"><PencilIcon aria-hidden className="w-4 h-4" /> Edit…</MenuItem>
245245
<MenuItem id="delete"><TrashIcon aria-hidden className="w-4 h-4" /> Delete…</MenuItem>
@@ -296,7 +296,7 @@ export function ExampleApp(): React.ReactNode {
296296
return (
297297
<Cell>
298298
<MenuTrigger>
299-
<Button aria-label="Actions" variant="icon">
299+
<Button aria-label="Actions" variant="secondary">
300300
<MoreHorizontal aria-hidden className="w-5 h-5" />
301301
</Button>
302302
<Menu onAction={action => onAction(item, action)}>

packages/dev/s2-docs/pages/react-aria/Button.mdx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import docs from 'docs:react-aria-components';
66
import {Button as VanillaButton} from 'vanilla-starter/Button';
77
import {Button as TailwindButton} from 'tailwind-starter/Button';
88
/* import {Button as MacroButton} from './ButtonExample'; */
9+
import vanillaDocs from 'docs:vanilla-starter/Button';
910
import tailwindDocs from 'docs:tailwind-starter/Button';
1011
import '../../tailwind/tailwind.css';
1112
import typesDocs from 'docs:@react-types/shared/src/events.d.ts';
@@ -19,9 +20,9 @@ export const tags = ['btn'];
1920
<ExampleSwitcher examples={['Vanilla CSS', 'Tailwind'/*, 'Style Macro'*/]}>
2021
<VisualExample
2122
component={VanillaButton}
22-
docs={docs.exports.Button}
23-
links={docs.links}
24-
props={['isPending', 'isDisabled']}
23+
docs={vanillaDocs.exports.Button}
24+
links={vanillaDocs.links}
25+
props={['variant', 'isPending', 'isDisabled']}
2526
initialProps={{children: 'Press me'}}
2627
type="vanilla"
2728
files={["starters/docs/src/Button.tsx", "starters/docs/src/Button.css"]} />
@@ -114,7 +115,7 @@ The `Button` component always represents a button semantically. To create a link
114115
"use client";
115116
import {Link} from 'react-aria-components';
116117

117-
<Link className="react-aria-Button" href="https://adobe.com/" target="_blank">
118+
<Link className="react-aria-Button button-base" href="https://adobe.com/" target="_blank">
118119
Adobe
119120
</Link>
120121
```

packages/dev/s2-docs/pages/react-aria/Calendar.mdx

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,11 @@ Set the `visibleDuration` prop and render multiple `CalendarGrid` elements to di
183183

184184
```tsx render docs={docs.exports.Calendar} links={docs.links} props={['visibleDuration', 'pageBehavior', 'firstDayOfWeek']} initialProps={{visibleDuration: {months: 2}}} wide
185185
"use client";
186-
import {Calendar, Heading, Button, CalendarGrid, CalendarCell} from 'react-aria-components';
186+
import {Calendar, Heading} from 'react-aria-components';
187+
import {CalendarGrid, CalendarCell} from 'vanilla-starter/Calendar';
188+
import {Button} from 'vanilla-starter/Button';
187189
import {useDateFormatter} from 'react-aria';
190+
import {ChevronLeft, ChevronRight} from 'lucide-react';
188191

189192
// TODO: move this into the starter example.
190193
function Example(props) {
@@ -201,18 +204,22 @@ function Example(props) {
201204
///- begin highlight -///
202205
/* PROPS */
203206
///- end highlight -///
204-
style={{display: 'flex', gap: 30, overflow: 'auto'}}
207+
style={{display: 'flex', gap: 12, overflow: 'auto'}}
205208
>
206209
{({state}) => (
207210
[...Array(props.visibleDuration.months).keys()].map(i => (
208211
<div key={i} style={{flex: 1}}>
209-
<header>
212+
<header style={{minHeight: 32}}>
210213
{i === 0 &&
211-
<Button slot="previous">◀</Button>
214+
<Button slot="previous" variant="quiet">
215+
<ChevronLeft />
216+
</Button>
212217
}
213-
<h2 style={{flex: 1, textAlign: 'center'}}>{monthFormatter.format(state.visibleRange.start.add({months: i}).toDate('UTC'))}</h2>
218+
<Heading>{monthFormatter.format(state.visibleRange.start.add({months: i}).toDate(state.timeZone))}</Heading>
214219
{i === props.visibleDuration.months - 1 &&
215-
<Button slot="next">▶</Button>
220+
<Button slot="next" variant="quiet">
221+
<ChevronRight />
222+
</Button>
216223
}
217224
</header>
218225
<CalendarGrid offset={{months: i}}>
@@ -265,19 +272,25 @@ You can also control the focused date via `CalendarStateContext`. This example s
265272

266273
```tsx render files={['packages/dev/s2-docs/pages/react-aria/MonthDropdown.tsx', 'packages/dev/s2-docs/pages/react-aria/YearDropdown.tsx']}
267274
"use client";
268-
import {Calendar, CalendarGrid, CalendarCell} from 'react-aria-components';
275+
import {Calendar} from 'react-aria-components';
276+
import {CalendarGrid, CalendarCell} from 'vanilla-starter/Calendar';
269277
import {MonthDropdown} from './MonthDropdown';
270278
import {YearDropdown} from './YearDropdown';
271279
import {Button} from 'vanilla-starter/Button';
280+
import {ChevronLeft, ChevronRight} from 'lucide-react';
272281

273282
<Calendar>
274283
<header style={{display: 'flex', gap: 4}}>
275-
<Button slot="previous">◀</Button>
284+
<Button slot="previous" variant="quiet">
285+
<ChevronLeft />
286+
</Button>
276287
{/*- begin highlight -*/}
277288
<MonthDropdown />
278289
<YearDropdown />
279290
{/*- end highlight -*/}
280-
<Button slot="next">▶</Button>
291+
<Button slot="next" variant="quiet">
292+
<ChevronRight />
293+
</Button>
281294
</header>
282295
<CalendarGrid>
283296
{(date) => <CalendarCell date={date} />}

packages/dev/s2-docs/pages/react-aria/Checkbox.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Use the `name` and `value` props to submit the checkbox to the server. Set the `
7070
"use client";
7171
import {Checkbox} from 'vanilla-starter/Checkbox';
7272
import {Button} from 'vanilla-starter/Button';
73-
import {Form} from 'react-aria-components';
73+
import {Form} from 'vanilla-starter/Form';;
7474

7575
<Form>
7676
<Checkbox

packages/dev/s2-docs/pages/react-aria/CheckboxGroup.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Use the `name` prop to submit the selected checkboxes to the server. Set the `is
7777
import {CheckboxGroup} from 'vanilla-starter/CheckboxGroup';
7878
import {Checkbox} from 'vanilla-starter/Checkbox';
7979
import {Button} from 'vanilla-starter/Button';
80-
import {Form} from 'react-aria-components';
80+
import {Form} from 'vanilla-starter/Form';;
8181

8282
<Form>
8383
<div style={{display: 'flex', gap: 32, flexWrap: 'wrap'}}>

packages/dev/s2-docs/pages/react-aria/ColorField.mdx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ export const tags = ['input'];
2020
docs={vanillaDocs.exports.ColorField}
2121
links={vanillaDocs.links}
2222
props={['label', 'colorSpace', 'channel', 'description', 'isDisabled']}
23-
initialProps={{label: 'Color', defaultValue: '#ff0000'}}
23+
initialProps={{label: 'Color', defaultValue: '#ff0000', placeholder: 'Enter a color'}}
2424
type="vanilla"
2525
files={["starters/docs/src/ColorField.tsx", "starters/docs/src/ColorField.css"]} />
2626
<VisualExample
2727
component={TailwindColorField}
2828
docs={vanillaDocs.exports.ColorField}
2929
links={vanillaDocs.links}
3030
props={['label', 'colorSpace', 'channel', 'description', 'isDisabled']}
31-
initialProps={{label: 'Color', defaultValue: '#ff0000'}}
31+
initialProps={{label: 'Color', defaultValue: '#ff0000', placeholder: 'Enter a color'}}
3232
type="tailwind"
3333
files={["starters/tailwind/src/ColorField.tsx", "starters/tailwind/src/index.css"]} />
3434
</ExampleSwitcher>
@@ -50,9 +50,10 @@ function Example() {
5050
<div>
5151
<ColorField
5252
label="Primary color"
53+
placeholder="Enter a color"
5354
value={value}
5455
onChange={setValue} />
55-
<pre style={{fontSize: 12}}>Current value: {value.toString('hex')}</pre>
56+
<pre style={{fontSize: 12}}>Current value: {value?.toString('hex')}</pre>
5657
</div>
5758
);
5859
}
@@ -75,6 +76,7 @@ function Example() {
7576
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
7677
<ColorField
7778
label="Hue"
79+
7880
value={color}
7981
onChange={setColor}
8082
/*- begin highlight -*/
@@ -115,6 +117,7 @@ function Example(props) {
115117
<ColorField
116118
{...props}
117119
label="Brand color"
120+
placeholder="Enter a color"
118121
///- begin highlight -///
119122
name="brandColor"
120123
isRequired />

packages/dev/s2-docs/pages/react-aria/ComboBox.mdx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const tags = ['autocomplete', 'search', 'typeahead', 'input'];
1414
<PageDescription>{docs.exports.ComboBox.description}</PageDescription>
1515

1616
<ExampleSwitcher>
17-
```tsx render docs={vanillaDocs.exports.ComboBox} links={vanillaDocs.links} props={['label', 'isDisabled']} initialProps={{label: 'Favorite Animal'}} type="vanilla" files={["starters/docs/src/ComboBox.tsx", "starters/docs/src/ComboBox.css"]}
17+
```tsx render docs={vanillaDocs.exports.ComboBox} links={vanillaDocs.links} props={['label', 'isDisabled']} initialProps={{label: 'Favorite Animal', placeholder: 'Select a flavor'}} type="vanilla" files={["starters/docs/src/ComboBox.tsx", "starters/docs/src/ComboBox.css"]}
1818
"use client";
1919
import {ComboBox, ComboBoxItem} from 'vanilla-starter/ComboBox';
2020

@@ -28,7 +28,7 @@ export const tags = ['autocomplete', 'search', 'typeahead', 'input'];
2828
</ComboBox>
2929
```
3030

31-
```tsx render docs={vanillaDocs.exports.ComboBox} links={vanillaDocs.links} props={['label', 'isDisabled']} initialProps={{label: 'Favorite Animal'}} type="tailwind" files={["starters/tailwind/src/ComboBox.tsx"]}
31+
```tsx render docs={vanillaDocs.exports.ComboBox} links={vanillaDocs.links} props={['label', 'isDisabled']} initialProps={{label: 'Favorite Animal', placeholder: 'Select a flavor'}} type="tailwind" files={["starters/tailwind/src/ComboBox.tsx"]}
3232
"use client";
3333
import {ComboBox, ComboBoxItem} from 'tailwind-starter/ComboBox';
3434

@@ -52,8 +52,8 @@ The following example shows a dynamic collection of items, grouped into sections
5252

5353
```tsx render
5454
"use client";
55-
import {ComboBox} from 'vanilla-starter/ComboBox';
56-
import {ListBoxSection, ListBoxItem, Collection, Header} from 'react-aria-components';
55+
import {ComboBox, ComboBoxItem} from 'vanilla-starter/ComboBox';
56+
import {ListBoxSection, Collection, Header} from 'react-aria-components';
5757

5858
function Example() {
5959
/*- begin collapse -*/
@@ -82,16 +82,21 @@ function Example() {
8282
/*- end collapse -*/
8383

8484
return (
85-
<ComboBox label="Preferred fruit or vegetable" items={options}>
85+
/*- begin highlight -*/
86+
<ComboBox
87+
label="Preferred fruit or vegetable"
88+
placeholder="Select an option"
89+
defaultItems={options}>
8690
{section => (
8791
<ListBoxSection id={section.name}>
8892
<Header>{section.name}</Header>
8993
<Collection items={section.children}>
90-
{item => <ListBoxItem id={item.name}>{item.name}</ListBoxItem>}
94+
{item => <ComboBoxItem id={item.name}>{item.name}</ComboBoxItem>}
9195
</Collection>
9296
</ListBoxSection>
9397
)}
9498
</ComboBox>
99+
/*- end highlight -*/
95100
);
96101
}
97102
```
@@ -112,7 +117,8 @@ function Example() {
112117
return (
113118
<div>
114119
<ComboBox
115-
label="Pick an animal"
120+
label="Favorite Animal"
121+
placeholder="Select an animal"
116122
/*- begin highlight -*/
117123
selectedKey={animal}
118124
onSelectionChange={setAnimal}>
@@ -148,6 +154,7 @@ function Example(props) {
148154
<ComboBox
149155
{...props}
150156
label="Favorite Animal"
157+
placeholder="Select an animal"
151158
/*- begin highlight -*/
152159
/* PROPS */
153160
inputValue={value}
@@ -215,7 +222,8 @@ function ControlledComboBox() {
215222
return (
216223
<div>
217224
<ComboBox
218-
label="Pick a engineering major"
225+
label="Engineering major"
226+
placeholder="Select a major"
219227
/*- begin highlight -*/
220228
defaultItems={options}
221229
selectedKey={fieldState.selectedKey}
@@ -249,6 +257,7 @@ function Example() {
249257
return (
250258
<ComboBox
251259
label="Favorite Animal"
260+
placeholder="Select an animal"
252261
allowsEmptyCollection
253262
inputValue={inputValue}
254263
onInputChange={setInputValue}>
@@ -278,11 +287,12 @@ Use the `name` prop to submit the `id` of the selected item to the server. Set t
278287
"use client";
279288
import {ComboBox, ComboBoxItem} from 'vanilla-starter/ComboBox';
280289
import {Button} from 'vanilla-starter/Button';
281-
import {Form} from 'react-aria-components';
290+
import {Form} from 'vanilla-starter/Form';;
282291

283292
<Form>
284293
<ComboBox
285294
label="Animal"
295+
placeholder="e.g. Cat"
286296
/*- begin highlight -*/
287297
name="animal"
288298
isRequired
@@ -309,7 +319,7 @@ Use the `menuTrigger` prop to control when the popover opens:
309319

310320
Use `allowsEmptyCollection` to keep the popover open when there are no items available in the list.
311321

312-
```tsx render wide docs={vanillaDocs.exports.ComboBox} links={vanillaDocs.links} props={['menuTrigger', 'allowsEmptyCollection']} initialProps={{label: 'Favorite Animal'}}
322+
```tsx render wide docs={vanillaDocs.exports.ComboBox} links={vanillaDocs.links} props={['menuTrigger', 'allowsEmptyCollection']} initialProps={{label: 'Favorite Animal', placeholder: 'Select an animal'}}
313323
"use client";
314324
import {ComboBox, ComboBoxItem} from 'vanilla-starter/ComboBox';
315325

0 commit comments

Comments
 (0)