@atlaskit/tabs 13.3.9 → 13.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/components/tab-list.js +20 -37
- package/dist/cjs/components/tab-panel.js +2 -10
- package/dist/cjs/components/tab.js +1 -7
- package/dist/cjs/components/tabs.js +32 -53
- package/dist/cjs/hooks.js +0 -14
- package/dist/cjs/index.js +0 -6
- package/dist/cjs/internal/colors.js +0 -8
- package/dist/cjs/internal/context.js +1 -2
- package/dist/cjs/internal/styles.js +6 -21
- package/dist/cjs/internal/utils.js +0 -3
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/components/tab-list.js +14 -18
- package/dist/es2019/components/tab-panel.js +0 -4
- package/dist/es2019/components/tab.js +0 -2
- package/dist/es2019/components/tabs.js +16 -16
- package/dist/es2019/hooks.js +0 -6
- package/dist/es2019/internal/styles.js +14 -13
- package/dist/es2019/internal/utils.js +0 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/components/tab-list.js +20 -28
- package/dist/esm/components/tab-panel.js +1 -5
- package/dist/esm/components/tab.js +1 -3
- package/dist/esm/components/tabs.js +32 -39
- package/dist/esm/hooks.js +0 -6
- package/dist/esm/internal/styles.js +6 -12
- package/dist/esm/internal/utils.js +0 -1
- package/dist/esm/version.json +1 -1
- package/package.json +3 -3
|
@@ -7,7 +7,6 @@ import { useTabList } from '../hooks';
|
|
|
7
7
|
import { TabContext } from '../internal/context';
|
|
8
8
|
import { getTabListStyles } from '../internal/styles';
|
|
9
9
|
import { onMouseDownBlur } from '../internal/utils';
|
|
10
|
-
|
|
11
10
|
/**
|
|
12
11
|
* __TabList__
|
|
13
12
|
*
|
|
@@ -29,52 +28,48 @@ const TabList = props => {
|
|
|
29
28
|
selected,
|
|
30
29
|
onChange
|
|
31
30
|
} = useTabList();
|
|
32
|
-
const ref = /*#__PURE__*/createRef();
|
|
31
|
+
const ref = /*#__PURE__*/createRef();
|
|
33
32
|
|
|
33
|
+
// Don't include any conditional children
|
|
34
34
|
const childrenArray = Children.toArray(children).filter(Boolean);
|
|
35
35
|
const length = childrenArray.length;
|
|
36
36
|
const tabListStyles = useMemo(() => getTabListStyles(mode), [mode]);
|
|
37
37
|
const selectTabByIndex = useCallback(index => {
|
|
38
38
|
var _ref$current;
|
|
39
|
-
|
|
40
39
|
const newSelectedNode = (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.querySelector(`[id='${tabsId}-${index}']`);
|
|
41
|
-
|
|
42
40
|
if (newSelectedNode) {
|
|
43
41
|
newSelectedNode.focus();
|
|
44
42
|
}
|
|
45
|
-
|
|
46
43
|
onChange(index);
|
|
47
44
|
}, [tabsId, ref, onChange]);
|
|
48
45
|
const onKeyDown = useCallback(e => {
|
|
49
46
|
if (!['ArrowRight', 'ArrowLeft', 'Home', 'End'].includes(e.key)) {
|
|
50
47
|
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
48
|
+
}
|
|
53
49
|
|
|
50
|
+
// preventing horizontal or vertical scroll
|
|
54
51
|
e.preventDefault();
|
|
55
52
|
const lastTabIndex = length - 1;
|
|
56
|
-
|
|
57
53
|
if (['Home', 'End'].includes(e.key)) {
|
|
58
54
|
const newSelected = e.key === 'Home' ? 0 : lastTabIndex;
|
|
59
55
|
selectTabByIndex(newSelected);
|
|
60
56
|
return;
|
|
61
|
-
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// We use aria-posinset so we don't rely on the selected variable
|
|
62
60
|
// If we used the selected variable this would regenerate each time
|
|
63
61
|
// and create an unstable reference
|
|
64
|
-
|
|
65
|
-
|
|
66
62
|
const selectedIndex = parseInt(e.currentTarget.getAttribute('aria-posinset') || '0') - 1;
|
|
67
63
|
const modifier = e.key === 'ArrowRight' ? 1 : -1;
|
|
68
64
|
let newSelected = selectedIndex + modifier;
|
|
69
|
-
|
|
70
65
|
if (newSelected < 0 || newSelected >= length) {
|
|
71
66
|
// Cycling focus to move from last to first and from first to last
|
|
72
67
|
newSelected = newSelected < 0 ? lastTabIndex : 0;
|
|
73
68
|
}
|
|
74
|
-
|
|
75
69
|
selectTabByIndex(newSelected);
|
|
76
|
-
}, [length, selectTabByIndex]);
|
|
70
|
+
}, [length, selectTabByIndex]);
|
|
77
71
|
|
|
72
|
+
// Memoized so the function isn't recreated each time
|
|
78
73
|
const getTabWithContext = useCallback(({
|
|
79
74
|
tab,
|
|
80
75
|
isSelected,
|
|
@@ -94,7 +89,8 @@ const TabList = props => {
|
|
|
94
89
|
},
|
|
95
90
|
key: index
|
|
96
91
|
}, tab), [length, onKeyDown, onChange, tabsId]);
|
|
97
|
-
return (
|
|
92
|
+
return (
|
|
93
|
+
// Only styles that affect the TabList itself have been applied via primitives.
|
|
98
94
|
// The other styles applied through the CSS prop are there for styling children
|
|
99
95
|
// through inheritance. This is important for custom cases that use the useTab(),
|
|
100
96
|
// which applies accessibility atributes that we use as a styling hook.
|
|
@@ -103,8 +99,9 @@ const TabList = props => {
|
|
|
103
99
|
role: "tablist",
|
|
104
100
|
display: "flex",
|
|
105
101
|
position: "relative",
|
|
106
|
-
padding: "
|
|
107
|
-
ref: ref
|
|
102
|
+
padding: "space.0",
|
|
103
|
+
ref: ref
|
|
104
|
+
// eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
108
105
|
,
|
|
109
106
|
css: tabListStyles
|
|
110
107
|
}, childrenArray.map((child, index) => getTabWithContext({
|
|
@@ -114,5 +111,4 @@ const TabList = props => {
|
|
|
114
111
|
})))
|
|
115
112
|
);
|
|
116
113
|
};
|
|
117
|
-
|
|
118
114
|
export default TabList;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
|
|
3
2
|
/** @jsx jsx */
|
|
4
3
|
import { Fragment } from 'react';
|
|
5
4
|
import { jsx } from '@emotion/react';
|
|
6
5
|
import { UNSAFE_Box as Box } from '@atlaskit/ds-explorations';
|
|
7
6
|
import { useTabPanel } from '../hooks';
|
|
8
|
-
|
|
9
7
|
// Note this is not being memoized as children is an unstable reference
|
|
10
|
-
|
|
11
8
|
/**
|
|
12
9
|
* __TabPanel__
|
|
13
10
|
*
|
|
@@ -27,5 +24,4 @@ const TabPanel = ({
|
|
|
27
24
|
as: "div"
|
|
28
25
|
}, tabPanelAttributes), jsx(Fragment, null, children));
|
|
29
26
|
};
|
|
30
|
-
|
|
31
27
|
export default TabPanel;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
|
|
3
2
|
/** @jsx jsx */
|
|
4
3
|
import { jsx } from '@emotion/react';
|
|
5
4
|
import { UNSAFE_Box as Box, UNSAFE_Text as Text } from '@atlaskit/ds-explorations';
|
|
6
5
|
import { useTab } from '../hooks';
|
|
7
|
-
|
|
8
6
|
/**
|
|
9
7
|
* __Tab__
|
|
10
8
|
*
|
|
@@ -10,15 +10,15 @@ import { onMouseDownBlur } from '../internal/utils';
|
|
|
10
10
|
const analyticsAttributes = {
|
|
11
11
|
componentName: 'tabs',
|
|
12
12
|
packageName: "@atlaskit/tabs",
|
|
13
|
-
packageVersion: "13.3.
|
|
13
|
+
packageVersion: "13.3.11"
|
|
14
14
|
};
|
|
15
|
-
|
|
16
15
|
const getTabPanelWithContext = ({
|
|
17
16
|
tabPanel,
|
|
18
17
|
index,
|
|
19
18
|
isSelected,
|
|
20
19
|
tabsId
|
|
21
|
-
}) =>
|
|
20
|
+
}) =>
|
|
21
|
+
// Ensure tabPanel exists in case it has been removed
|
|
22
22
|
tabPanel && jsx(TabPanelContext.Provider, {
|
|
23
23
|
value: {
|
|
24
24
|
role: 'tabpanel',
|
|
@@ -30,6 +30,7 @@ tabPanel && jsx(TabPanelContext.Provider, {
|
|
|
30
30
|
},
|
|
31
31
|
key: index
|
|
32
32
|
}, tabPanel);
|
|
33
|
+
|
|
33
34
|
/**
|
|
34
35
|
* __Tabs__
|
|
35
36
|
*
|
|
@@ -39,8 +40,6 @@ tabPanel && jsx(TabPanelContext.Provider, {
|
|
|
39
40
|
* - [Code](https://atlassian.design/components/tabs/code)
|
|
40
41
|
* - [Usage](https://atlassian.design/components/tabs/usage)
|
|
41
42
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
43
|
const Tabs = props => {
|
|
45
44
|
const {
|
|
46
45
|
shouldUnmountTabPanelOnChange = false,
|
|
@@ -57,22 +56,21 @@ const Tabs = props => {
|
|
|
57
56
|
} = useGlobalTheme();
|
|
58
57
|
const [selectedState, setSelected] = useState(SelectedType || defaultSelected || 0);
|
|
59
58
|
const selected = SelectedType === undefined ? selectedState : SelectedType;
|
|
60
|
-
const childrenArray = Children.toArray(children)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
const childrenArray = Children.toArray(children)
|
|
60
|
+
// Don't include any conditional children
|
|
61
|
+
.filter(child => Boolean(child));
|
|
62
|
+
// First child should be a tabList followed by tab panels
|
|
63
|
+
const [tabList, ...tabPanels] = childrenArray;
|
|
64
64
|
|
|
65
|
+
// Keep track of visited and add to a set
|
|
65
66
|
const visited = useRef(new Set([selected]));
|
|
66
|
-
|
|
67
67
|
if (!visited.current.has(selected)) {
|
|
68
68
|
visited.current.add(selected);
|
|
69
69
|
}
|
|
70
|
-
|
|
71
70
|
const onChange = useCallback((index, analyticsEvent) => {
|
|
72
71
|
if (onChangeProp) {
|
|
73
72
|
onChangeProp(index, analyticsEvent);
|
|
74
73
|
}
|
|
75
|
-
|
|
76
74
|
setSelected(index);
|
|
77
75
|
}, [onChangeProp]);
|
|
78
76
|
const onChangeAnalytics = usePlatformLeafEventHandler({
|
|
@@ -86,7 +84,8 @@ const Tabs = props => {
|
|
|
86
84
|
index: selected,
|
|
87
85
|
isSelected: true,
|
|
88
86
|
tabsId: id
|
|
89
|
-
}) :
|
|
87
|
+
}) :
|
|
88
|
+
// If a panel has already been visited, don't unmount it
|
|
90
89
|
Array.from(visited.current).map(tabIndex => getTabPanelWithContext({
|
|
91
90
|
tabPanel: tabPanels[tabIndex],
|
|
92
91
|
index: tabIndex,
|
|
@@ -94,7 +93,8 @@ const Tabs = props => {
|
|
|
94
93
|
tabsId: id
|
|
95
94
|
}));
|
|
96
95
|
const tabsStyles = useMemo(() => getTabsStyles(mode), [mode]);
|
|
97
|
-
return (
|
|
96
|
+
return (
|
|
97
|
+
// Only styles that affect the Tabs container itself have been applied via primitives.
|
|
98
98
|
// The other styles applied through the CSS prop are there for styling children
|
|
99
99
|
// through inheritance. This is important for custom cases that use the useTabPanel(),
|
|
100
100
|
// which applies accessibility atributes that we use as a styling hook.
|
|
@@ -108,7 +108,8 @@ const Tabs = props => {
|
|
|
108
108
|
minHeight: '0%',
|
|
109
109
|
flexBasis: '100%',
|
|
110
110
|
flexGrow: 1
|
|
111
|
-
}
|
|
111
|
+
}
|
|
112
|
+
// eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
112
113
|
,
|
|
113
114
|
css: tabsStyles
|
|
114
115
|
}, jsx(TabListContext.Provider, {
|
|
@@ -120,5 +121,4 @@ const Tabs = props => {
|
|
|
120
121
|
}, tabList), jsx(Fragment, null, tabPanelsWithContext))
|
|
121
122
|
);
|
|
122
123
|
};
|
|
123
|
-
|
|
124
124
|
export default Tabs;
|
package/dist/es2019/hooks.js
CHANGED
|
@@ -2,28 +2,22 @@ import { useContext } from 'react';
|
|
|
2
2
|
import { TabContext, TabListContext, TabPanelContext } from './internal/context';
|
|
3
3
|
export const useTab = () => {
|
|
4
4
|
const tabData = useContext(TabContext);
|
|
5
|
-
|
|
6
5
|
if (tabData == null || typeof tabData === 'undefined') {
|
|
7
6
|
throw Error('@atlaskit/tabs: A Tab must have a TabList parent.');
|
|
8
7
|
}
|
|
9
|
-
|
|
10
8
|
return tabData;
|
|
11
9
|
};
|
|
12
10
|
export const useTabList = () => {
|
|
13
11
|
const tabListData = useContext(TabListContext);
|
|
14
|
-
|
|
15
12
|
if (tabListData === null || typeof tabListData === 'undefined') {
|
|
16
13
|
throw Error('@atlaskit/tabs: A TabList must have a Tabs parent.');
|
|
17
14
|
}
|
|
18
|
-
|
|
19
15
|
return tabListData;
|
|
20
16
|
};
|
|
21
17
|
export const useTabPanel = () => {
|
|
22
18
|
const tabPanelData = useContext(TabPanelContext);
|
|
23
|
-
|
|
24
19
|
if (tabPanelData === null || typeof tabPanelData === 'undefined') {
|
|
25
20
|
throw Error('@atlaskit/tabs: A TabPanel must have a Tabs parent.');
|
|
26
21
|
}
|
|
27
|
-
|
|
28
22
|
return tabPanelData;
|
|
29
23
|
};
|
|
@@ -8,8 +8,9 @@ const tabTopBottomPadding = `${gridSize / 2}px`;
|
|
|
8
8
|
const underlineHeight = '2px';
|
|
9
9
|
const highContrastFocusStyles = {
|
|
10
10
|
outline: '1px solid'
|
|
11
|
-
};
|
|
11
|
+
};
|
|
12
12
|
|
|
13
|
+
// Required so the focus ring is visible in high contrast mode
|
|
13
14
|
const highContrastFocusRing = {
|
|
14
15
|
'@media screen and (forced-colors: active), screen and (-ms-high-contrast: active)': {
|
|
15
16
|
'&:focus-visible': highContrastFocusStyles,
|
|
@@ -18,16 +19,13 @@ const highContrastFocusRing = {
|
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
21
|
};
|
|
21
|
-
|
|
22
22
|
const tabFocusStyles = mode => ({
|
|
23
23
|
boxShadow: `0 0 0 2px ${getTabPanelFocusColor(mode)} inset`,
|
|
24
24
|
borderRadius: borderRadius,
|
|
25
25
|
outline: 'none'
|
|
26
26
|
});
|
|
27
|
-
|
|
28
27
|
const getTabPanelStyles = mode => ({
|
|
29
28
|
flexGrow: 1,
|
|
30
|
-
|
|
31
29
|
/*
|
|
32
30
|
NOTE min-height set to 0% because of Firefox bug
|
|
33
31
|
FF http://stackoverflow.com/questions/28636832/firefox-overflow-y-not-working-with-nested-flexbox
|
|
@@ -41,8 +39,8 @@ const getTabPanelStyles = mode => ({
|
|
|
41
39
|
},
|
|
42
40
|
...highContrastFocusRing
|
|
43
41
|
});
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
export const getTabsStyles = mode =>
|
|
43
|
+
// eslint-disable-next-line @repo/internal/styles/no-exported-styles
|
|
46
44
|
css({
|
|
47
45
|
'& [role="tabpanel"]': getTabPanelStyles(mode),
|
|
48
46
|
// The hidden attribute doesn't work on flex elements
|
|
@@ -62,17 +60,18 @@ const tabLineStyles = {
|
|
|
62
60
|
left: tabLeftRightPadding,
|
|
63
61
|
right: tabLeftRightPadding
|
|
64
62
|
};
|
|
65
|
-
export const getTabListStyles = mode =>
|
|
63
|
+
export const getTabListStyles = mode =>
|
|
64
|
+
// eslint-disable-next-line @repo/internal/styles/no-exported-styles
|
|
66
65
|
css({
|
|
67
66
|
'& [role="tab"]': getTabStyles(mode),
|
|
68
67
|
fontWeight: "var(--ds-font-weight-medium, 500)",
|
|
69
|
-
'&::before': {
|
|
68
|
+
'&::before': {
|
|
69
|
+
...tabLineStyles,
|
|
70
70
|
height: underlineHeight,
|
|
71
71
|
// This line is not a border so the selected line is visible in high contrast mode
|
|
72
72
|
backgroundColor: getTabLineColor(mode).lineColor
|
|
73
73
|
}
|
|
74
74
|
});
|
|
75
|
-
|
|
76
75
|
const tabPanelFocusStyles = mode => {
|
|
77
76
|
const colors = getTabColors(mode);
|
|
78
77
|
return {
|
|
@@ -85,7 +84,6 @@ const tabPanelFocusStyles = mode => {
|
|
|
85
84
|
}
|
|
86
85
|
};
|
|
87
86
|
};
|
|
88
|
-
|
|
89
87
|
export const getTabStyles = mode => {
|
|
90
88
|
const colors = getTabColors(mode);
|
|
91
89
|
return {
|
|
@@ -101,7 +99,8 @@ export const getTabStyles = mode => {
|
|
|
101
99
|
'&:hover': {
|
|
102
100
|
// TODO: interaction states will be reviewed in DSP-1438
|
|
103
101
|
color: colors.hoverLabelColor,
|
|
104
|
-
'&::after': {
|
|
102
|
+
'&::after': {
|
|
103
|
+
...tabLineStyles,
|
|
105
104
|
borderBottom: `${underlineHeight} solid ${getTabLineColor(mode).hoveredColor}`,
|
|
106
105
|
height: 0
|
|
107
106
|
}
|
|
@@ -109,7 +108,8 @@ export const getTabStyles = mode => {
|
|
|
109
108
|
'&:active': {
|
|
110
109
|
// TODO: interaction states will be reviewed in DSP-1438
|
|
111
110
|
color: colors.activeLabelColor,
|
|
112
|
-
'&::after': {
|
|
111
|
+
'&::after': {
|
|
112
|
+
...tabLineStyles,
|
|
113
113
|
borderBottom: `${underlineHeight} solid ${getTabLineColor(mode).activeColor}`,
|
|
114
114
|
height: 0
|
|
115
115
|
}
|
|
@@ -121,7 +121,8 @@ export const getTabStyles = mode => {
|
|
|
121
121
|
...highContrastFocusRing,
|
|
122
122
|
'&[aria-selected="true"]': {
|
|
123
123
|
color: colors.selectedColor,
|
|
124
|
-
'&::after': {
|
|
124
|
+
'&::after': {
|
|
125
|
+
...tabLineStyles,
|
|
125
126
|
// This line is a border so it is visible in high contrast mode
|
|
126
127
|
borderBottom: `${underlineHeight} solid ${getTabLineColor(mode).selectedColor}`,
|
|
127
128
|
height: 0
|
package/dist/es2019/version.json
CHANGED
|
@@ -7,7 +7,6 @@ import { useTabList } from '../hooks';
|
|
|
7
7
|
import { TabContext } from '../internal/context';
|
|
8
8
|
import { getTabListStyles } from '../internal/styles';
|
|
9
9
|
import { onMouseDownBlur } from '../internal/utils';
|
|
10
|
-
|
|
11
10
|
/**
|
|
12
11
|
* __TabList__
|
|
13
12
|
*
|
|
@@ -19,17 +18,15 @@ import { onMouseDownBlur } from '../internal/utils';
|
|
|
19
18
|
*/
|
|
20
19
|
var TabList = function TabList(props) {
|
|
21
20
|
var children = props.children;
|
|
22
|
-
|
|
23
21
|
var _useGlobalTheme = useGlobalTheme(),
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
mode = _useGlobalTheme.mode;
|
|
26
23
|
var _useTabList = useTabList(),
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var ref = /*#__PURE__*/createRef(); // Don't include any conditional children
|
|
24
|
+
tabsId = _useTabList.tabsId,
|
|
25
|
+
selected = _useTabList.selected,
|
|
26
|
+
onChange = _useTabList.onChange;
|
|
27
|
+
var ref = /*#__PURE__*/createRef();
|
|
32
28
|
|
|
29
|
+
// Don't include any conditional children
|
|
33
30
|
var childrenArray = Children.toArray(children).filter(Boolean);
|
|
34
31
|
var length = childrenArray.length;
|
|
35
32
|
var tabListStyles = useMemo(function () {
|
|
@@ -37,50 +34,44 @@ var TabList = function TabList(props) {
|
|
|
37
34
|
}, [mode]);
|
|
38
35
|
var selectTabByIndex = useCallback(function (index) {
|
|
39
36
|
var _ref$current;
|
|
40
|
-
|
|
41
37
|
var newSelectedNode = (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.querySelector("[id='".concat(tabsId, "-").concat(index, "']"));
|
|
42
|
-
|
|
43
38
|
if (newSelectedNode) {
|
|
44
39
|
newSelectedNode.focus();
|
|
45
40
|
}
|
|
46
|
-
|
|
47
41
|
onChange(index);
|
|
48
42
|
}, [tabsId, ref, onChange]);
|
|
49
43
|
var onKeyDown = useCallback(function (e) {
|
|
50
44
|
if (!['ArrowRight', 'ArrowLeft', 'Home', 'End'].includes(e.key)) {
|
|
51
45
|
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
46
|
+
}
|
|
54
47
|
|
|
48
|
+
// preventing horizontal or vertical scroll
|
|
55
49
|
e.preventDefault();
|
|
56
50
|
var lastTabIndex = length - 1;
|
|
57
|
-
|
|
58
51
|
if (['Home', 'End'].includes(e.key)) {
|
|
59
52
|
var _newSelected = e.key === 'Home' ? 0 : lastTabIndex;
|
|
60
|
-
|
|
61
53
|
selectTabByIndex(_newSelected);
|
|
62
54
|
return;
|
|
63
|
-
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// We use aria-posinset so we don't rely on the selected variable
|
|
64
58
|
// If we used the selected variable this would regenerate each time
|
|
65
59
|
// and create an unstable reference
|
|
66
|
-
|
|
67
|
-
|
|
68
60
|
var selectedIndex = parseInt(e.currentTarget.getAttribute('aria-posinset') || '0') - 1;
|
|
69
61
|
var modifier = e.key === 'ArrowRight' ? 1 : -1;
|
|
70
62
|
var newSelected = selectedIndex + modifier;
|
|
71
|
-
|
|
72
63
|
if (newSelected < 0 || newSelected >= length) {
|
|
73
64
|
// Cycling focus to move from last to first and from first to last
|
|
74
65
|
newSelected = newSelected < 0 ? lastTabIndex : 0;
|
|
75
66
|
}
|
|
76
|
-
|
|
77
67
|
selectTabByIndex(newSelected);
|
|
78
|
-
}, [length, selectTabByIndex]);
|
|
68
|
+
}, [length, selectTabByIndex]);
|
|
79
69
|
|
|
70
|
+
// Memoized so the function isn't recreated each time
|
|
80
71
|
var getTabWithContext = useCallback(function (_ref) {
|
|
81
72
|
var tab = _ref.tab,
|
|
82
|
-
|
|
83
|
-
|
|
73
|
+
isSelected = _ref.isSelected,
|
|
74
|
+
index = _ref.index;
|
|
84
75
|
return jsx(TabContext.Provider, {
|
|
85
76
|
value: {
|
|
86
77
|
onClick: function onClick() {
|
|
@@ -99,7 +90,8 @@ var TabList = function TabList(props) {
|
|
|
99
90
|
key: index
|
|
100
91
|
}, tab);
|
|
101
92
|
}, [length, onKeyDown, onChange, tabsId]);
|
|
102
|
-
return (
|
|
93
|
+
return (
|
|
94
|
+
// Only styles that affect the TabList itself have been applied via primitives.
|
|
103
95
|
// The other styles applied through the CSS prop are there for styling children
|
|
104
96
|
// through inheritance. This is important for custom cases that use the useTab(),
|
|
105
97
|
// which applies accessibility atributes that we use as a styling hook.
|
|
@@ -108,8 +100,9 @@ var TabList = function TabList(props) {
|
|
|
108
100
|
role: "tablist",
|
|
109
101
|
display: "flex",
|
|
110
102
|
position: "relative",
|
|
111
|
-
padding: "
|
|
112
|
-
ref: ref
|
|
103
|
+
padding: "space.0",
|
|
104
|
+
ref: ref
|
|
105
|
+
// eslint-disable-next-line @repo/internal/react/consistent-css-prop-usage
|
|
113
106
|
,
|
|
114
107
|
css: tabListStyles
|
|
115
108
|
}, childrenArray.map(function (child, index) {
|
|
@@ -121,5 +114,4 @@ var TabList = function TabList(props) {
|
|
|
121
114
|
}))
|
|
122
115
|
);
|
|
123
116
|
};
|
|
124
|
-
|
|
125
117
|
export default TabList;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
|
|
3
2
|
/** @jsx jsx */
|
|
4
3
|
import { Fragment } from 'react';
|
|
5
4
|
import { jsx } from '@emotion/react';
|
|
6
5
|
import { UNSAFE_Box as Box } from '@atlaskit/ds-explorations';
|
|
7
6
|
import { useTabPanel } from '../hooks';
|
|
8
|
-
|
|
9
7
|
// Note this is not being memoized as children is an unstable reference
|
|
10
|
-
|
|
11
8
|
/**
|
|
12
9
|
* __TabPanel__
|
|
13
10
|
*
|
|
@@ -19,12 +16,11 @@ import { useTabPanel } from '../hooks';
|
|
|
19
16
|
*/
|
|
20
17
|
var TabPanel = function TabPanel(_ref) {
|
|
21
18
|
var children = _ref.children,
|
|
22
|
-
|
|
19
|
+
testId = _ref.testId;
|
|
23
20
|
var tabPanelAttributes = useTabPanel();
|
|
24
21
|
return jsx(Box, _extends({
|
|
25
22
|
testId: testId,
|
|
26
23
|
as: "div"
|
|
27
24
|
}, tabPanelAttributes), jsx(Fragment, null, children));
|
|
28
25
|
};
|
|
29
|
-
|
|
30
26
|
export default TabPanel;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
|
|
3
2
|
/** @jsx jsx */
|
|
4
3
|
import { jsx } from '@emotion/react';
|
|
5
4
|
import { UNSAFE_Box as Box, UNSAFE_Text as Text } from '@atlaskit/ds-explorations';
|
|
6
5
|
import { useTab } from '../hooks';
|
|
7
|
-
|
|
8
6
|
/**
|
|
9
7
|
* __Tab__
|
|
10
8
|
*
|
|
@@ -16,7 +14,7 @@ import { useTab } from '../hooks';
|
|
|
16
14
|
*/
|
|
17
15
|
export default function Tab(_ref) {
|
|
18
16
|
var children = _ref.children,
|
|
19
|
-
|
|
17
|
+
testId = _ref.testId;
|
|
20
18
|
var tabAttributes = useTab();
|
|
21
19
|
return jsx(Box, _extends({
|
|
22
20
|
as: "div",
|