-
Notifications
You must be signed in to change notification settings - Fork 261
fix: Forward getId to useTabsModel to ensure custom ids work when registering items #4141
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
Changes from all commits
b85218f
8f4c80e
d2b330c
b47ca0d
c0ba1f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,21 +110,26 @@ export const useTabsModel = createModelHook({ | |
| unregisterPanel: panels.events.unregisterItem, | ||
| }; | ||
|
|
||
| const menu = useMenuModel( | ||
| useMenuModel.mergeConfig(config.menuConfig, { | ||
| id: `menu-${model.state.id}`, | ||
| items: overflowItems, | ||
| nonInteractiveIds: state.nonInteractiveIds.filter(key => !state.hiddenIds.includes(key)), | ||
| onSelect(data) { | ||
| menu.events.hide(); | ||
| events.select(data); | ||
| }, | ||
| onShow() { | ||
| // Always select the first item when the menu is opened | ||
| menu.events.goToFirst(); | ||
| }, | ||
| }) | ||
| ); | ||
| const mergedMenuConfig = useMenuModel.mergeConfig(config.menuConfig, { | ||
| id: `menu-${model.state.id}`, | ||
| items: overflowItems, | ||
| // `getId`/`getTextValue` aren't callbacks or guards, so `mergeConfig` would let these | ||
| // unconditionally clobber a `menuConfig.getId`/`getTextValue` override. Fall back to the | ||
| // top-level Tabs config only when the caller hasn't set one on `menuConfig` directly. | ||
| getId: config.menuConfig?.getId || getId, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to add a Cypress test with a custom getId & overflow menu scenario?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I update the story and we have a test for OverFlowTabs in cypress, so by changing the story, it should still pass!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah ok. I'm still trying to figure out when we add tests for specific scenarios in Cypress tests vs just having them in Storybook.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its confusing sometimes we use storybook for cypress |
||
| getTextValue: config.menuConfig?.getTextValue || config.getTextValue, | ||
| nonInteractiveIds: state.nonInteractiveIds.filter(key => !state.hiddenIds.includes(key)), | ||
| onSelect(data) { | ||
| menu.events.hide(); | ||
| events.select(data); | ||
| }, | ||
| onShow() { | ||
| // Always select the first item when the menu is opened | ||
| menu.events.goToFirst(); | ||
| }, | ||
| }); | ||
|
|
||
| const menu = useMenuModel(mergedMenuConfig); | ||
|
|
||
| return { | ||
| ...model, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,23 +7,24 @@ import {px2rem} from '@workday/canvas-kit-styling'; | |
| import {system} from '@workday/canvas-tokens-web'; | ||
|
|
||
| type MyTabItem = { | ||
| id: string; | ||
| contextId: string; | ||
| text: React.ReactNode; | ||
| contents: string; | ||
| }; | ||
|
|
||
| export const OverflowTabs = () => { | ||
| const [items] = React.useState<MyTabItem[]>([ | ||
| {id: 'first', text: 'First Tab', contents: 'Contents of First Tab'}, | ||
| {id: 'second', text: 'Second Tab', contents: 'Contents of Second Tab'}, | ||
| {id: 'third', text: 'Third Tab', contents: 'Contents of Third Tab'}, | ||
| {id: 'fourth', text: 'Fourth Tab', contents: 'Contents of Fourth Tab'}, | ||
| {id: 'fifth', text: 'Fifth Tab', contents: 'Contents of Fifth Tab'}, | ||
| {id: 'sixth', text: 'Sixth Tab', contents: 'Contents of Sixth Tab'}, | ||
| {id: 'seventh', text: 'Seventh Tab', contents: 'Contents of Seventh Tab'}, | ||
| {contextId: 'first', text: 'First Tab', contents: 'Contents of First Tab'}, | ||
| {contextId: 'second', text: 'Second Tab', contents: 'Contents of Second Tab'}, | ||
| {contextId: 'third', text: 'Third Tab', contents: 'Contents of Third Tab'}, | ||
| {contextId: 'fourth', text: 'Fourth Tab', contents: 'Contents of Fourth Tab'}, | ||
| {contextId: 'fifth', text: 'Fifth Tab', contents: 'Contents of Fifth Tab'}, | ||
| {contextId: 'sixth', text: 'Sixth Tab', contents: 'Contents of Sixth Tab'}, | ||
| {contextId: 'seventh', text: 'Seventh Tab', contents: 'Contents of Seventh Tab'}, | ||
| ]); | ||
| const model = useTabsModel({ | ||
| items, | ||
| getId: (item: MyTabItem) => item.contextId, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed this story to match a real work example |
||
| }); | ||
| const [containerWidth, setContainerWidth] = React.useState('100%'); | ||
| return ( | ||
|
|
||
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 the real change, this was returning undefined