-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: S2 Selectbox Updates #8748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I still need to take a closer look at the design tokens and the tests but many of the issues have been addressed. |
Build successful! 🎉 |
Build successful! 🎉 |
render: (args) => { | ||
const {selectionMode, orientation, isDisabled} = args as any; | ||
return ( | ||
<SelectBoxGroup selectionMode={selectionMode} orientation={orientation} isDisabled={isDisabled} UNSAFE_style={{gridTemplateColumns: 'repeat(2, 1fr)'}}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can just spread args onto here once you have the types fixed
we shouldn't use UNSAFE_style in our documentation, I'd just get rid of it, and if you need to constrain the area so it doesn't go across the entire screen, just add a wrapping div with an appropriate width. Check other storybooks for examples
{/* Enabled items with dynamic illustrations */} | ||
}} | ||
{...args} | ||
UNSAFE_style={{gridTemplateColumns: 'repeat(4, 1fr)'}}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
@@ -313,7 +220,7 @@ function InteractiveExamplesStory() { | |||
} | |||
|
|||
export const InteractiveExamples: Story = { | |||
render: () => <InteractiveExamplesStory /> | |||
render: (args) => <InteractiveExamplesStory {...args} /> | |||
}; | |||
|
|||
export const AllSlotCombinations: Story = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a better story for chromatic
jest.spyOn(window.HTMLElement.prototype, 'clientWidth', 'get').mockImplementation(() => 100); | ||
jest.spyOn(window.HTMLElement.prototype, 'clientHeight', 'get').mockImplementation(() => 100); | ||
jest.spyOn(window.HTMLElement.prototype, 'scrollHeight', 'get').mockImplementation(() => 50); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need to mock all these? this is usually for virtualised components, which this isn't
const options = screen.getAllByRole('option'); | ||
const option1 = options.find(option => option.textContent?.includes('Option 1'))!; | ||
|
||
await userEvent.click(option1); | ||
await user.click(option1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably make use of the test-util ListBoxTester
in order to do interactions and avoid things like
const options = screen.getAllByRole('option');
const option1 = options.find(option => option.textContent?.includes('Option 1'))!;
https://react-spectrum.adobe.com/react-aria/ListBox.html#testing
These three lines would be something like
toggleOptionSelection({option: 1})
Then it's easier to write tests which are agnostic of keyboard or mouse, so you can run both on the same series of tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
gridTemplateColumns: `repeat(${numColumns}, 1fr)`, | ||
...UNSAFE_style | ||
}}> | ||
{...otherProps} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
selectionBehavior="replace" doesn't seem to be working as expected. Probably not something we need to address right now. It seems like something that wouldn't be used with this component anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also shouldSelectOnPressUp
doesn't seem to work as expected. I think this is one we could omit from the types, I don't think it makes sense to have here. A few more aren't working as well, like shouldFocusWrap
. Definitely not something we need now though, I would be in favor of omitting them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just confirmed with the team that we can omit these props for now.
Build successful! 🎉 |
## API Changes
@react-spectrum/s2/@react-spectrum/s2:SelectBoxGroup SelectBoxGroup <T> {
UNSAFE_className?: UnsafeClassName
UNSAFE_style?: CSSProperties
aria-describedby?: string
aria-details?: string
aria-label?: string
aria-labelledby?: string
autoFocus?: boolean | FocusStrategy
children: ReactNode
className?: ClassNameOrFunction<ListBoxRenderProps>
- defaultSelectedKeys?: Selection
+ defaultSelectedKeys?: 'all' | Iterable<Key>
+ dependencies?: ReadonlyArray<any>
disabledKeys?: Iterable<Key>
disallowEmptySelection?: boolean
+ dragAndDropHooks?: DragAndDropHooks<NoInfer<T>>
escapeKeyBehavior?: 'clearSelection' | 'none' = 'clearSelection'
- gutterWidth?: 'default' | 'compact' | 'spacious' = 'default'
id?: string
isDisabled?: boolean
- numColumns?: number = 2
+ items?: Iterable<T>
+ layout?: 'stack' | 'grid' = 'stack'
onAction?: (Key) => void
onBlur?: (FocusEvent<Target>) => void
onFocus?: (FocusEvent<Target>) => void
onFocusChange?: (boolean) => void
onSelectionChange?: (Selection) => void
orientation?: Orientation = 'vertical'
- selectedKeys?: Selection
+ renderEmptyState?: (ListBoxRenderProps) => ReactNode
+ selectedKeys?: 'all' | Iterable<Key>
selectionBehavior?: SelectionBehavior = "toggle"
selectionMode?: 'single' | 'multiple' = 'single'
shouldFocusOnHover?: boolean
shouldFocusWrap?: boolean
shouldSelectOnPressUp?: boolean
- showCheckbox?: boolean = false
slot?: string | null
style?: StyleOrFunction<ListBoxRenderProps>
styles?: StylesProp
} /@react-spectrum/s2:SelectBoxGroupProps SelectBoxGroupProps <T> {
UNSAFE_className?: UnsafeClassName
UNSAFE_style?: CSSProperties
aria-describedby?: string
aria-details?: string
aria-label?: string
aria-labelledby?: string
autoFocus?: boolean | FocusStrategy
children: ReactNode
className?: ClassNameOrFunction<ListBoxRenderProps>
- defaultSelectedKeys?: Selection
+ defaultSelectedKeys?: 'all' | Iterable<Key>
+ dependencies?: ReadonlyArray<any>
disabledKeys?: Iterable<Key>
disallowEmptySelection?: boolean
+ dragAndDropHooks?: DragAndDropHooks<NoInfer<T>>
escapeKeyBehavior?: 'clearSelection' | 'none' = 'clearSelection'
- gutterWidth?: 'default' | 'compact' | 'spacious' = 'default'
id?: string
isDisabled?: boolean
- numColumns?: number = 2
+ items?: Iterable<T>
+ layout?: 'stack' | 'grid' = 'stack'
onAction?: (Key) => void
onBlur?: (FocusEvent<Target>) => void
onFocus?: (FocusEvent<Target>) => void
onFocusChange?: (boolean) => void
onSelectionChange?: (Selection) => void
orientation?: Orientation = 'vertical'
- selectedKeys?: Selection
+ renderEmptyState?: (ListBoxRenderProps) => ReactNode
+ selectedKeys?: 'all' | Iterable<Key>
selectionBehavior?: SelectionBehavior = "toggle"
selectionMode?: 'single' | 'multiple' = 'single'
shouldFocusOnHover?: boolean
shouldFocusWrap?: boolean
shouldSelectOnPressUp?: boolean
- showCheckbox?: boolean = false
slot?: string | null
style?: StyleOrFunction<ListBoxRenderProps>
styles?: StylesProp
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Closes
things to look out for that we discussed when we tested selectbox:
✅ Pull Request Checklist:
📝 Test Instructions:
Run the
SelectBoxGroup.test.tsx
file and observe the SelectBox s2 component withyarn start:s2
🧢 Your Project: