Skip to content

Commit b2229ad

Browse files
committed
Address nits
1 parent 92f1504 commit b2229ad

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

packages/experimental/TabList/src/Tab/useTab.win32.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,14 @@ export const useTab = (props: TabProps): TabInfo => {
9292

9393
React.useEffect(() => {
9494
updateTabRef(tabKey, componentRef);
95+
// Intentionally disable exhaustive-deps warning this and the following hooks because the hook shouldn't run whenever the excluded dependencies change.
9596
// eslint-disable-next-line react-hooks/exhaustive-deps
96-
}, [componentRef]);
97+
}, [tabKey, componentRef]);
9798

9899
React.useEffect(() => {
99100
updateDisabledTabs(tabKey, disabled);
100101
// eslint-disable-next-line react-hooks/exhaustive-deps
101-
}, [disabled]);
102+
}, [tabKey, disabled]);
102103

103104
/**
104105
* Continuing from `handlePressAndDeferFocus`, once we have updated the selection state, we can safely set focus to the correct tab so

packages/experimental/TabList/src/TabList/TabList.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ export const TabList = compose<TabListType>({
3636

3737
const { disabled, defaultTabbableElement, isCircularNavigation, vertical, ...mergedProps } = mergeProps(tablist.props, final);
3838

39-
const { animatedIndicatorStyles, canShowAnimatedIndicator, disabled: disabledState, layout, selectedKey } = tablist.state;
39+
const { animatedIndicatorStyles, canShowAnimatedIndicator, disabled: tablistDisabledState, layout, selectedKey } = tablist.state;
4040

4141
return (
4242
<TabListContext.Provider
4343
// Passes in the selected key and a hook function to update the newly selected tab and call the client's onTabsClick callback.
4444
value={tablist.state}
4545
>
4646
<Slots.container
47-
disabled={disabled || disabledState}
47+
disabled={disabled || tablistDisabledState}
4848
defaultTabbableElement={defaultTabbableElement}
4949
focusZoneDirection={vertical ? 'vertical' : 'horizontal'}
5050
isCircularNavigation={isCircularNavigation}

packages/experimental/TabList/src/TabList/TabList.types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export interface TabListState {
8787
setInvoked?: (invoked: boolean) => void;
8888

8989
/**
90-
* Setter for the selected Tab's ref to set as the default tabbable element in the FocusZone
90+
* Setter for the focused Tab's ref to set as the default tabbable element in the FocusZone
9191
*/
9292
setFocusedTabRef: (ref: React.RefObject<any>) => void;
9393

packages/experimental/TabList/src/TabList/useTabList.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ export const useTabList = (props: TabListProps): TabListInfo => {
4444
const [tabKeys, setTabKeys] = React.useState<string[]>([]);
4545
const [allTabsDisabled, setAllTabsDisabled] = React.useState(false);
4646

47-
// These
47+
// These maps are used to switch tab focus in the event the selected tab is disabled. React refs are used as storage because updating the maps shouldn't trigger a re-render.
4848
const tabRefMap = React.useRef<{ [key: string]: React.RefObject<View> }>({}).current;
4949
const disabledStateMap = React.useRef<{ [key: string]: boolean }>({}).current;
5050

51-
const updateTabRef = (key: string, ref: React.RefObject<View>) => (tabRefMap[key] = ref);
51+
const updateTabRef = React.useCallback((key: string, ref: React.RefObject<View>) => (tabRefMap[key] = ref), [tabRefMap]);
5252
const updateDisabledTabs = React.useCallback(
5353
(key: string, isDisabled: boolean) => {
5454
disabledStateMap[key] = isDisabled;

0 commit comments

Comments
 (0)