File tree Expand file tree Collapse file tree 2 files changed +10
-8
lines changed
react/advanced-compound-components/04-compound-component-tabs/practice Expand file tree Collapse file tree 2 files changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -4,9 +4,9 @@ import { wrapEvent } from '../../utils'
4
4
// You know what to do 😉
5
5
6
6
// Hint: You probably need three contexts
7
- const TabsContext = createContext ( )
8
- const TabContext = createContext ( )
9
- const PanelContext = createContext ( )
7
+ const TabsContext = createContext ( ) // For passing general top-level info down
8
+ const TabListContext = createContext ( ) // For passing index down from TabList to Tab
9
+ const TabPanelsContext = createContext ( ) // Same but index down from TabPanels to TabPanel
10
10
11
11
export const Tabs = ( { children, ...props } ) => {
12
12
return (
@@ -29,9 +29,9 @@ export const TabList = ({ children, ...props }) => {
29
29
30
30
export const Tab = ( { children, ...props } ) => {
31
31
return (
32
- < div { ...props } data-tab = "" >
32
+ < button { ...props } data-tab = "" role = "tab ">
33
33
{ children }
34
- </ div >
34
+ </ button >
35
35
)
36
36
}
37
37
Original file line number Diff line number Diff line change @@ -10,9 +10,11 @@ export function TaskOne() {
10
10
</ li >
11
11
< li >
12
12
We're going to need to know the index of each tab. You'll need to iterate the `children` of
13
- `TabList` which are the Tabs. Use `React.Children.map` and pass the index of the Tab to it.
14
- You could use `React.cloneElement` but there are some drawbacks. Another way is to create
15
- another type of context so we can pass index down from `TabList` to `Tab`.
13
+ `TabList`. The children of `TabList` is `Tab`. Use `React.Children.map` to get the index and
14
+ pass it to each Tab. You could use `React.cloneElement` but there are some drawbacks.
15
+ Another way is to create another type of context so we can pass index down from `TabList` to
16
+ `Tab`. Note that you'll need a different context provider than the main `TabsContext`. We
17
+ made a context for you already called `TabListContext`
16
18
</ li >
17
19
< li >
18
20
For the panels, use the HTML `hidden` attribute to hide panels that are not active. Note,
You can’t perform that action at this time.
0 commit comments