Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@react-stately/tabs/src/useTabListState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function useTabListState<T extends object>(props: TabListStateOptions<T>)
useEffect(() => {
// Ensure a tab is always selected (in case no selected key was specified or if selected item was deleted from collection)
let selectedKey = currentSelectedKey;
if (props.selectedKey == null && (selectionManager.isEmpty || selectedKey == null || !collection.getItem(selectedKey))) {
if (props.selectedKey === undefined && (selectionManager.isEmpty || selectedKey == null || !collection.getItem(selectedKey))) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my understanding is that we only want to do this in the uncontrolled case, seeing as we don't do this when props.selectedKey is a non-null Key

selectedKey = findDefaultSelectedKey(collection, state.disabledKeys);
if (selectedKey != null) {
// directly set selection because replace/toggle selection won't consider disabled keys
Expand Down
2 changes: 1 addition & 1 deletion packages/react-aria-components/stories/Tabs.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default {
export type TabsStory = StoryFn<typeof Tabs>;

export const TabsExample: TabsStory = () => {
let [url, setUrl] = useState('/FoR');
let [url, setUrl] = useState<string | null>(null);

return (
<RouterProvider navigate={setUrl}>
Expand Down
2 changes: 1 addition & 1 deletion packages/react-aria-components/test/Tabs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ describe('Tabs', () => {
expect(tabs[2].tagName).toBe('A');
expect(tabs[2]).toHaveAttribute('href', '/Emp');

expect(tabs[0]).toHaveAttribute('aria-selected', 'true');
expect(tabs[1]).toHaveAttribute('aria-selected', 'false');
await user.click(tabs[1]);
expect(tabs[1]).toHaveAttribute('aria-selected', 'true');

Expand Down