Skip to content

Commit 62eb6ce

Browse files
devongovettLFDanLu
andauthored
chore: SelectBox audit (#8766)
* chore: SelectBox audit * fix chromatic lint * fix tests and lint --------- Co-authored-by: Daniel Lu <dl1644@gmail.com>
1 parent a2caea4 commit 62eb6ce

File tree

4 files changed

+279
-256
lines changed

4 files changed

+279
-256
lines changed

packages/@react-spectrum/s2/chromatic/SelectBoxGroup.stories.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,18 @@ type Story = StoryObj<typeof SelectBoxGroup>;
3131
export const VerticalOrientation: Story = {
3232
render: () => (
3333
<div style={{width: 600}}>
34-
<SelectBoxGroup
34+
<SelectBoxGroup
35+
aria-label="Vertical"
3536
orientation="vertical"
3637
onSelectionChange={action('onSelectionChange')}>
37-
<SelectBox value="text-only">
38+
<SelectBox id="text-only" textValue="V: Text Only">
3839
<Text slot="label">V: Text Only</Text>
3940
</SelectBox>
40-
<SelectBox value="illustration-text">
41+
<SelectBox id="illustration-text" textValue="V: Illustration + Text">
4142
<Server />
4243
<Text slot="label">V: Illustration + Text</Text>
4344
</SelectBox>
44-
<SelectBox value="illustration-desc">
45+
<SelectBox id="illustration-desc" textValue="Send">
4546
<PaperAirplane />
4647
</SelectBox>
4748
</SelectBoxGroup>
@@ -52,21 +53,22 @@ export const VerticalOrientation: Story = {
5253
export const HorizontalOrientation: Story = {
5354
render: () => (
5455
<div style={{width: 800}}>
55-
<SelectBoxGroup
56+
<SelectBoxGroup
57+
aria-label="Horizontal"
5658
orientation="horizontal"
5759
onSelectionChange={action('onSelectionChange')}>
58-
<SelectBox value="text-only">
60+
<SelectBox id="text-only" textValue="Title Only">
5961
<Text slot="label">Title Only</Text>
6062
</SelectBox>
61-
<SelectBox value="illustration-text">
63+
<SelectBox id="illustration-text" textValue="Illustration + Title">
6264
<Server />
6365
<Text slot="label">Illustration + Title</Text>
6466
</SelectBox>
65-
<SelectBox value="text-desc">
67+
<SelectBox id="text-desc" textValue="Title + Description">
6668
<Text slot="label">Title + Description</Text>
6769
<Text slot="description">Additional description</Text>
6870
</SelectBox>
69-
<SelectBox value="h-all">
71+
<SelectBox id="h-all" textValue="Illustration + Title + Description">
7072
<Server />
7173
<Text slot="label">Illustration + Title + Description</Text>
7274
<Text slot="description">Full horizontal layout with all elements</Text>

packages/@react-spectrum/s2/src/SelectBoxGroup.tsx

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* governing permissions and limitations under the License.
1010
*/
1111

12+
import {baseColor, focusRing, style} from '../style' with {type: 'macro'};
1213
import {box, iconStyles} from './Checkbox';
1314
import Checkmark from '../ui-icons/Checkmark';
1415
import {
@@ -19,20 +20,24 @@ import {
1920
ListBoxProps,
2021
Provider
2122
} from 'react-aria-components';
22-
import {DOMRef, DOMRefValue, GlobalDOMAttributes, Orientation} from '@react-types/shared';
23-
import {focusRing, style} from '../style' with {type: 'macro'};
23+
import {DOMRef, DOMRefValue, GlobalDOMAttributes, Key, Orientation} from '@react-types/shared';
2424
import {getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'};
2525
import {IllustrationContext} from '../src/Icon';
2626
import {pressScale} from './pressScale';
2727
import React, {createContext, forwardRef, ReactNode, useContext, useMemo, useRef} from 'react';
2828
import {TextContext} from './Content';
2929
import {useSpectrumContextProps} from './useSpectrumContextProps';
3030

31-
export interface SelectBoxGroupProps<T> extends StyleProps, Omit<ListBoxProps<T>, keyof GlobalDOMAttributes | 'layout' | 'dragAndDropHooks' | 'dependencies' | 'renderEmptyState' | 'children' | 'onAction' | 'shouldFocusOnHover' | 'selectionBehavior' | 'style' | 'className'> {
31+
export interface SelectBoxGroupProps<T> extends StyleProps, Omit<ListBoxProps<T>, keyof GlobalDOMAttributes | 'layout' | 'dragAndDropHooks' | 'dependencies' | 'renderEmptyState' | 'children' | 'onAction' | 'shouldFocusOnHover' | 'selectionBehavior' | 'shouldSelectOnPressUp' | 'shouldFocusWrap' | 'style' | 'className'> {
3232
/**
3333
* The SelectBox elements contained within the SelectBoxGroup.
3434
*/
3535
children: ReactNode,
36+
/**
37+
* The layout direction of the content in each SelectBox.
38+
* @default 'vertical'
39+
*/
40+
orientation?: Orientation,
3641
/**
3742
* The selection mode for the SelectBoxGroup.
3843
* @default 'single'
@@ -45,12 +50,14 @@ export interface SelectBoxGroupProps<T> extends StyleProps, Omit<ListBoxProps<T>
4550
}
4651

4752
export interface SelectBoxProps extends StyleProps {
53+
/** The unique id of the SelectBox. */
54+
id?: Key,
55+
/** A string representation of the SelectBox's contents, used for features like typeahead. */
56+
textValue?: string,
57+
/** An accessibility label for this item. */
58+
'aria-label'?: string,
4859
/**
49-
* The value of the SelectBox.
50-
*/
51-
value: string,
52-
/**
53-
* The label for the element.
60+
* The contents of the SelectBox.
5461
*/
5562
children: ReactNode,
5663
/**
@@ -76,6 +83,7 @@ const selectBoxStyles = style({
7683
gridAutoRows: '1fr',
7784
position: 'relative',
7885
font: 'ui',
86+
cursor: 'default',
7987
boxSizing: 'border-box',
8088
overflow: 'hidden',
8189
width: {
@@ -176,7 +184,7 @@ const selectBoxStyles = style({
176184
},
177185
backgroundColor: {
178186
default: 'layer-2',
179-
isDisabled: 'layer-1'
187+
isDisabled: 'disabled'
180188
},
181189
color: {
182190
isDisabled: 'disabled'
@@ -196,12 +204,12 @@ const illustrationContainer = style({
196204
alignSelf: 'center',
197205
justifySelf: 'center',
198206
minSize: 48,
199-
color: {
200-
isDisabled: 'disabled',
201-
isHovered: 'gray-900'
202-
},
203-
opacity: {
204-
isDisabled: 0.4
207+
'--iconPrimary': {
208+
type: 'color',
209+
value: {
210+
default: baseColor('neutral'),
211+
isDisabled: 'disabled'
212+
}
205213
}
206214
});
207215

@@ -222,8 +230,7 @@ const descriptionText = style({
222230
}
223231
},
224232
color: {
225-
default: 'neutral',
226-
isHovered: 'gray-900',
233+
default: baseColor('neutral'),
227234
isDisabled: 'disabled'
228235
}
229236
});
@@ -254,20 +261,29 @@ const labelText = style({
254261
}
255262
},
256263
color: {
257-
default: 'neutral',
258-
isHovered: 'gray-900',
264+
default: baseColor('neutral'),
259265
isDisabled: 'disabled'
260266
}
261267
});
262268

263269
const gridStyles = style<{orientation?: Orientation}>({
264270
display: 'grid',
265271
gridAutoRows: '1fr',
266-
gap: 16,
272+
gap: 24,
273+
justifyContent: 'center',
274+
'--size': {
275+
type: 'width',
276+
value: {
277+
orientation: {
278+
horizontal: 368,
279+
vertical: 170
280+
}
281+
}
282+
},
267283
gridTemplateColumns: {
268284
orientation: {
269-
horizontal: 'repeat(auto-fit, minmax(368px, 1fr))',
270-
vertical: 'repeat(auto-fit, minmax(170px, 1fr))'
285+
horizontal: 'repeat(auto-fit, var(--size))',
286+
vertical: 'repeat(auto-fit, var(--size))'
271287
}
272288
}
273289
}, getAllowedOverrides());
@@ -276,7 +292,7 @@ const gridStyles = style<{orientation?: Orientation}>({
276292
* SelectBox is a single selectable item in a SelectBoxGroup.
277293
*/
278294
export function SelectBox(props: SelectBoxProps): ReactNode {
279-
let {children, value, isDisabled: individualDisabled = false, UNSAFE_style, UNSAFE_className, styles, ...otherProps} = props;
295+
let {children, isDisabled: individualDisabled = false, UNSAFE_style, UNSAFE_className, styles, ...otherProps} = props;
280296

281297
let {
282298
orientation = 'vertical',
@@ -288,8 +304,6 @@ export function SelectBox(props: SelectBoxProps): ReactNode {
288304

289305
return (
290306
<ListBoxItem
291-
id={value}
292-
textValue={value}
293307
isDisabled={isDisabled}
294308
ref={ref}
295309
className={renderProps => (UNSAFE_className || '') + selectBoxStyles({
@@ -364,6 +378,7 @@ export const SelectBoxGroup = /*#__PURE__*/ forwardRef(function SelectBoxGroup<T
364378
isDisabled = false,
365379
UNSAFE_className,
366380
UNSAFE_style,
381+
styles,
367382
...otherProps
368383
} = props;
369384

@@ -382,7 +397,7 @@ export const SelectBoxGroup = /*#__PURE__*/ forwardRef(function SelectBoxGroup<T
382397
<ListBox
383398
selectionMode={selectionMode}
384399
layout="grid"
385-
className={(UNSAFE_className || '') + gridStyles({orientation})}
400+
className={(UNSAFE_className || '') + gridStyles({orientation}, styles)}
386401
style={UNSAFE_style}
387402
{...otherProps}>
388403
<SelectBoxContext.Provider value={selectBoxContextValue}>

0 commit comments

Comments
 (0)