File tree 2 files changed +6
-10
lines changed
packages/circuit-ui/components/Tabs
2 files changed +6
-10
lines changed Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ describe('Tabs', () => {
73
73
it ( 'should go to the previous tab on left arrow press' , async ( ) => {
74
74
render (
75
75
< Tabs
76
- initialSelectedId = "b"
76
+ initialSelectedIndex = { 1 }
77
77
items = { [
78
78
{ id : 'a' , tab : 'tab-a' , panel : 'panel-a' } ,
79
79
{ id : 'b' , tab : 'tab-b' , panel : 'panel-b' } ,
Original file line number Diff line number Diff line change @@ -29,11 +29,11 @@ import { TabPanel } from './components/TabPanel/index.js';
29
29
30
30
export interface TabsProps extends TabListProps {
31
31
/**
32
- * The id of the initially selected tab.
32
+ * The index of the initially selected tab.
33
33
*
34
- * @default items[0].id
34
+ * @default 0
35
35
*/
36
- initialSelectedId ?: string ;
36
+ initialSelectedIndex ?: number ;
37
37
/**
38
38
* A collection of tabs with an id, the tab label, and panel content.
39
39
*/
@@ -44,12 +44,8 @@ export interface TabsProps extends TabListProps {
44
44
} [ ] ;
45
45
}
46
46
47
- export function Tabs ( {
48
- items,
49
- initialSelectedId = items [ 0 ] . id ,
50
- ...props
51
- } : TabsProps ) {
52
- const [ selectedId , setSelectedId ] = useState ( initialSelectedId ) ;
47
+ export function Tabs ( { items, initialSelectedIndex = 0 , ...props } : TabsProps ) {
48
+ const [ selectedId , setSelectedId ] = useState ( items [ initialSelectedIndex ] ?. id ) ;
53
49
54
50
const handleTabKeyDown = ( event : KeyboardEvent ) => {
55
51
const selectedIndex = items . findIndex ( ( item ) => item . id === selectedId ) ;
You can’t perform that action at this time.
0 commit comments