@zohodesk/components 1.0.0-temp-262.1 → 1.0.0-temp-262.2
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 +6 -0
- package/es/v1/Tab/Tab.js +46 -8
- package/es/v1/Tab/TabList.js +11 -3
- package/es/v1/Tab/__tests__/Tab.spec.js +187 -0
- package/es/v1/Tab/__tests__/__snapshots__/Tab.spec.js.snap +1 -1
- package/es/v1/Tab/css/Tab_v1.module.css +47 -6
- package/es/v1/Tab/css/tab.cva.js +9 -0
- package/es/v1/Tab/props/propTypes.js +11 -0
- package/lib/v1/Tab/Tab.js +46 -7
- package/lib/v1/Tab/TabList.js +14 -3
- package/lib/v1/Tab/__tests__/Tab.spec.js +214 -0
- package/lib/v1/Tab/__tests__/__snapshots__/Tab.spec.js.snap +1 -1
- package/lib/v1/Tab/css/Tab_v1.module.css +47 -6
- package/lib/v1/Tab/css/tab.cva.js +9 -0
- package/lib/v1/Tab/props/propTypes.js +11 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
- **v1 Tab** - `Tab` (and data-driven `TabList` items) accept `renderAction`: an interactive node rendered beside the `role="tab"` button instead of inside it. The `tab` slot then styles a wrapper (`data-selected` / `data-disabled`) that also carries `customId`, `testId`, `dataSelectorId` and `tourId`; new `tabTrigger` / `tabAction` slots. Not shown in the overflow menu.
|
|
6
|
+
- **v1 Tab** - Data-driven `TabList` items accept a per-item `customClass`.
|
|
7
|
+
- **v1 Tab** - A data-driven `TabList` no longer clips its overflow when `customProps.popup.isAbsolutePositioningNeeded` is `true`, so the inline more menu is no longer hidden.
|
|
8
|
+
|
|
3
9
|
## 1.6.34
|
|
4
10
|
|
|
5
11
|
- **CheckBox** - Fixed the CSS Utility class ordering to resolve the position property conflict between the disabled and tick classes.
|
package/es/v1/Tab/Tab.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
2
|
|
|
3
3
|
import React from 'react';
|
|
4
|
-
import { Tab as TabCore } from "./core";
|
|
4
|
+
import { Tab as TabCore, useTabsData } from "./core";
|
|
5
5
|
import mergeProps from '@zohodesk/utils/es/mergeProps';
|
|
6
6
|
import renderNode, { isRenderable } from '@zohodesk/utils/es/renderNode';
|
|
7
7
|
import FlexContainer from '@zohodesk/layout/es/Flex/FlexContainer';
|
|
@@ -30,6 +30,7 @@ const Tab = props => {
|
|
|
30
30
|
renderIcon,
|
|
31
31
|
renderBefore,
|
|
32
32
|
renderAfter,
|
|
33
|
+
renderAction,
|
|
33
34
|
onClick,
|
|
34
35
|
getRef,
|
|
35
36
|
customClass,
|
|
@@ -61,6 +62,9 @@ const Tab = props => {
|
|
|
61
62
|
textTransform: textTransformFromGroup,
|
|
62
63
|
textTruncate: textTruncateFromGroup
|
|
63
64
|
} = useTabsStyle('Tab');
|
|
65
|
+
const {
|
|
66
|
+
selectedValue
|
|
67
|
+
} = useTabsData('Tab');
|
|
64
68
|
const textTransform = textTransformFromGroup || TEXT_TRANSFORM.CAPITAL;
|
|
65
69
|
const textTruncate = textTruncateFromGroup || TEXT_TRUNCATE.CLAMP;
|
|
66
70
|
const isTextOnly = labelStyle === LABEL_STYLE.TEXT;
|
|
@@ -85,19 +89,22 @@ const Tab = props => {
|
|
|
85
89
|
}
|
|
86
90
|
|
|
87
91
|
const classes = getClasses(styleOverrides);
|
|
88
|
-
const isAnchor = !!href;
|
|
92
|
+
const isAnchor = !!href; // With an action the visual tab becomes a wrapper around the role="tab"
|
|
93
|
+
// trigger, so an interactive action never nests inside the <button>.
|
|
94
|
+
|
|
95
|
+
const hasAction = isRenderable(renderAction);
|
|
89
96
|
const elementProps = mergeProps({
|
|
90
|
-
className: classes.tab,
|
|
97
|
+
className: hasAction ? classes.tabTrigger : classes.tab,
|
|
91
98
|
href: isAnchor && !isDisabled ? href : undefined,
|
|
92
99
|
target: isAnchor ? target : undefined,
|
|
93
100
|
rel: isAnchor ? rel : undefined,
|
|
94
|
-
'data-tour': tourId,
|
|
101
|
+
'data-tour': hasAction ? undefined : tourId,
|
|
95
102
|
'aria-label': accessibleName,
|
|
96
103
|
'data-title': title
|
|
97
104
|
}, {
|
|
98
105
|
onClick
|
|
99
106
|
}, tabAttributes, a11yAttributes);
|
|
100
|
-
|
|
107
|
+
const trigger = /*#__PURE__*/React.createElement(TabCore, _extends({
|
|
101
108
|
value: value,
|
|
102
109
|
isDisabled: isDisabled,
|
|
103
110
|
isAnchor: isAnchor,
|
|
@@ -106,9 +113,9 @@ const Tab = props => {
|
|
|
106
113
|
alignItems: "center",
|
|
107
114
|
justifyContent: justifyContent
|
|
108
115
|
}, elementProps, {
|
|
109
|
-
customId: customId,
|
|
110
|
-
testId: testId,
|
|
111
|
-
"data-selector-id": dataSelectorId
|
|
116
|
+
customId: hasAction ? undefined : customId,
|
|
117
|
+
testId: hasAction ? undefined : testId,
|
|
118
|
+
"data-selector-id": hasAction ? undefined : dataSelectorId
|
|
112
119
|
}), ({
|
|
113
120
|
isSelected
|
|
114
121
|
}) => {
|
|
@@ -147,6 +154,37 @@ const Tab = props => {
|
|
|
147
154
|
$tagAttributes_container: tabTextAttributes
|
|
148
155
|
}), text) : null, children, isRenderable(renderAfter) ? renderNode(renderAfter, slot) : null);
|
|
149
156
|
});
|
|
157
|
+
|
|
158
|
+
if (!hasAction) {
|
|
159
|
+
return trigger;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const isSelected = value === selectedValue;
|
|
163
|
+
const actionSlot = {
|
|
164
|
+
value,
|
|
165
|
+
isSelected,
|
|
166
|
+
isDisabled
|
|
167
|
+
};
|
|
168
|
+
return /*#__PURE__*/React.createElement(FlexContainer, {
|
|
169
|
+
as: "span",
|
|
170
|
+
display: "inlineFlex",
|
|
171
|
+
alignItems: "center",
|
|
172
|
+
justifyContent: justifyContent,
|
|
173
|
+
customClass: classes.tab,
|
|
174
|
+
customId: customId,
|
|
175
|
+
testId: testId,
|
|
176
|
+
customAttributes: {
|
|
177
|
+
role: 'presentation',
|
|
178
|
+
'data-selected': String(isSelected),
|
|
179
|
+
'data-disabled': String(!!isDisabled),
|
|
180
|
+
'data-tour': tourId,
|
|
181
|
+
'data-selector-id': dataSelectorId
|
|
182
|
+
}
|
|
183
|
+
}, trigger, /*#__PURE__*/React.createElement(FlexItem, {
|
|
184
|
+
as: "span",
|
|
185
|
+
shrink: "0",
|
|
186
|
+
customClass: classes.tabAction
|
|
187
|
+
}, renderNode(renderAction, actionSlot)));
|
|
150
188
|
};
|
|
151
189
|
|
|
152
190
|
export default Tab;
|
package/es/v1/Tab/TabList.js
CHANGED
|
@@ -64,9 +64,15 @@ const TabList = props => {
|
|
|
64
64
|
});
|
|
65
65
|
const styleValue = useMemo(() => ({ ...styleContext,
|
|
66
66
|
hasOverflow: isDataDriven
|
|
67
|
-
}), [styleContext, isDataDriven]);
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
}), [styleContext, isDataDriven]); // An inline (absolutely positioned) more menu renders inside the list, so
|
|
68
|
+
// clipping the list would hide it; a portalled menu escapes the clip.
|
|
69
|
+
|
|
70
|
+
const isMoreMenuInline = !!popupOptions.isAbsolutePositioningNeeded;
|
|
71
|
+
const scroll = hasScroll ? orientation === ORIENTATION.VERTICAL ? 'vertical' : 'horizontal' : isDataDriven && !isMoreMenuInline ? 'hidden' : undefined;
|
|
72
|
+
|
|
73
|
+
const getClassSignature = itemClass => itemClass ? Object.keys(itemClass).map(slot => `${slot}:${itemClass[slot] || ''}`).join(',') : '';
|
|
74
|
+
|
|
75
|
+
const itemsSignature = `${labelStyle || ''}\u0001${position || ''}\u0001` + (items || DUMMY_ARRAY).map(item => `${item.value}|${item.text || ''}|${item.iconName || ''}|${item.isDisabled ? 1 : 0}|${item.renderBefore ? 1 : 0}|${item.renderAfter ? 1 : 0}|${item.renderAction ? 1 : 0}|${getClassSignature(item.customClass)}`).join('\u0000');
|
|
70
76
|
const dataList = useMemo(() => items || DUMMY_ARRAY, [itemsSignature]);
|
|
71
77
|
const {
|
|
72
78
|
parentRef,
|
|
@@ -121,6 +127,8 @@ const TabList = props => {
|
|
|
121
127
|
renderIcon: item.renderIcon,
|
|
122
128
|
renderBefore: item.renderBefore,
|
|
123
129
|
renderAfter: item.renderAfter,
|
|
130
|
+
renderAction: item.renderAction,
|
|
131
|
+
customClass: item.customClass,
|
|
124
132
|
customId: item.customId,
|
|
125
133
|
testId: item.testId,
|
|
126
134
|
dataSelectorId: item.dataSelectorId
|
|
@@ -1099,4 +1099,191 @@ describe('Tab - Behaviour', () => {
|
|
|
1099
1099
|
|
|
1100
1100
|
expect(document.querySelector('input[name="search"]')).toBeNull();
|
|
1101
1101
|
});
|
|
1102
|
+
});
|
|
1103
|
+
/*
|
|
1104
|
+
* Per-item customClass and renderAction exist for the ticket detail-view
|
|
1105
|
+
* subtab strip: a custom-lookup tab caps its own width, and the conversation
|
|
1106
|
+
* tab carries an interactive view-type menu that must not nest inside the
|
|
1107
|
+
* <button role="tab">.
|
|
1108
|
+
*/
|
|
1109
|
+
|
|
1110
|
+
describe('Tab - Item customClass, renderAction and an inline more menu', () => {
|
|
1111
|
+
test('a data-driven item customClass lands on that tab only', () => {
|
|
1112
|
+
render( /*#__PURE__*/React.createElement(Tabs, {
|
|
1113
|
+
uniqueId: "tabs"
|
|
1114
|
+
}, /*#__PURE__*/React.createElement(TabList, {
|
|
1115
|
+
ariaLabel: "Cities",
|
|
1116
|
+
minVisibleTabs: ITEMS.length,
|
|
1117
|
+
items: ITEMS.map(item => item.value === 'b' ? { ...item,
|
|
1118
|
+
customClass: {
|
|
1119
|
+
tab: 'capped-tab'
|
|
1120
|
+
}
|
|
1121
|
+
} : item)
|
|
1122
|
+
})));
|
|
1123
|
+
expect(screen.getByRole('tab', {
|
|
1124
|
+
name: 'Bravo'
|
|
1125
|
+
}).className).toContain('capped-tab');
|
|
1126
|
+
expect(screen.getByRole('tab', {
|
|
1127
|
+
name: 'Alpha'
|
|
1128
|
+
}).className).not.toContain('capped-tab');
|
|
1129
|
+
expect(screen.getByRole('tab', {
|
|
1130
|
+
name: 'Charlie'
|
|
1131
|
+
}).className).not.toContain('capped-tab');
|
|
1132
|
+
});
|
|
1133
|
+
test('changing only an item customClass re-renders that tab', () => {
|
|
1134
|
+
const renderList = tabClass => /*#__PURE__*/React.createElement(Tabs, {
|
|
1135
|
+
uniqueId: "tabs"
|
|
1136
|
+
}, /*#__PURE__*/React.createElement(TabList, {
|
|
1137
|
+
ariaLabel: "Cities",
|
|
1138
|
+
minVisibleTabs: ITEMS.length,
|
|
1139
|
+
items: ITEMS.map(item => item.value === 'a' ? { ...item,
|
|
1140
|
+
customClass: {
|
|
1141
|
+
tab: tabClass
|
|
1142
|
+
}
|
|
1143
|
+
} : item)
|
|
1144
|
+
}));
|
|
1145
|
+
|
|
1146
|
+
const {
|
|
1147
|
+
rerender
|
|
1148
|
+
} = render(renderList('first-class'));
|
|
1149
|
+
rerender(renderList('second-class'));
|
|
1150
|
+
const tab = screen.getByRole('tab', {
|
|
1151
|
+
name: 'Alpha'
|
|
1152
|
+
});
|
|
1153
|
+
expect(tab.className).toContain('second-class');
|
|
1154
|
+
expect(tab.className).not.toContain('first-class');
|
|
1155
|
+
});
|
|
1156
|
+
test('renderAction renders beside the tab button, never inside it', () => {
|
|
1157
|
+
render( /*#__PURE__*/React.createElement(Tabs, {
|
|
1158
|
+
uniqueId: "tabs",
|
|
1159
|
+
selectedValue: "one"
|
|
1160
|
+
}, /*#__PURE__*/React.createElement(TabList, {
|
|
1161
|
+
ariaLabel: "Cities"
|
|
1162
|
+
}, /*#__PURE__*/React.createElement(Tab, {
|
|
1163
|
+
value: "one",
|
|
1164
|
+
text: "one",
|
|
1165
|
+
customId: "one_Tab",
|
|
1166
|
+
renderAction: () => /*#__PURE__*/React.createElement("button", {
|
|
1167
|
+
type: "button"
|
|
1168
|
+
}, "view")
|
|
1169
|
+
}), /*#__PURE__*/React.createElement(Tab, {
|
|
1170
|
+
value: "two",
|
|
1171
|
+
text: "two"
|
|
1172
|
+
}))));
|
|
1173
|
+
const tab = screen.getByRole('tab', {
|
|
1174
|
+
name: 'one'
|
|
1175
|
+
});
|
|
1176
|
+
const action = screen.getByRole('button', {
|
|
1177
|
+
name: 'view'
|
|
1178
|
+
});
|
|
1179
|
+
expect(tab.contains(action)).toBe(false);
|
|
1180
|
+
expect(tab.querySelector('button')).toBeNull();
|
|
1181
|
+
/* The wrapper is the visual tab: it holds both, carries the state and the ids. */
|
|
1182
|
+
|
|
1183
|
+
const wrapper = tab.parentElement;
|
|
1184
|
+
expect(wrapper.contains(action)).toBe(true);
|
|
1185
|
+
expect(wrapper).toHaveAttribute('data-selected', 'true');
|
|
1186
|
+
expect(wrapper).toHaveAttribute('data-id', 'one_Tab');
|
|
1187
|
+
expect(tab).not.toHaveAttribute('data-id', 'one_Tab');
|
|
1188
|
+
expect(wrapper.className).toContain('tab');
|
|
1189
|
+
expect(tab.className).toContain('tabTrigger');
|
|
1190
|
+
/* The wrapper is the direct child the adaptive renderer measures. */
|
|
1191
|
+
|
|
1192
|
+
expect(wrapper.parentElement).toBe(screen.getByRole('tablist'));
|
|
1193
|
+
});
|
|
1194
|
+
test('without renderAction the tab DOM is unchanged', () => {
|
|
1195
|
+
render( /*#__PURE__*/React.createElement(Tabs, {
|
|
1196
|
+
uniqueId: "tabs"
|
|
1197
|
+
}, /*#__PURE__*/React.createElement(TabList, {
|
|
1198
|
+
ariaLabel: "Cities"
|
|
1199
|
+
}, /*#__PURE__*/React.createElement(Tab, {
|
|
1200
|
+
value: "one",
|
|
1201
|
+
text: "one"
|
|
1202
|
+
}))));
|
|
1203
|
+
const tab = screen.getByRole('tab', {
|
|
1204
|
+
name: 'one'
|
|
1205
|
+
});
|
|
1206
|
+
expect(tab.parentElement).toBe(screen.getByRole('tablist'));
|
|
1207
|
+
expect(tab.className).not.toContain('tabTrigger');
|
|
1208
|
+
});
|
|
1209
|
+
test('the wrapper follows selection and the trigger still selects on click', () => {
|
|
1210
|
+
const onChange = jest.fn();
|
|
1211
|
+
render( /*#__PURE__*/React.createElement(Tabs, {
|
|
1212
|
+
uniqueId: "tabs",
|
|
1213
|
+
defaultValue: "one",
|
|
1214
|
+
onChange: onChange
|
|
1215
|
+
}, /*#__PURE__*/React.createElement(TabList, {
|
|
1216
|
+
ariaLabel: "Cities"
|
|
1217
|
+
}, /*#__PURE__*/React.createElement(Tab, {
|
|
1218
|
+
value: "one",
|
|
1219
|
+
text: "one"
|
|
1220
|
+
}), /*#__PURE__*/React.createElement(Tab, {
|
|
1221
|
+
value: "two",
|
|
1222
|
+
text: "two",
|
|
1223
|
+
renderAction: () => /*#__PURE__*/React.createElement("span", null, "action")
|
|
1224
|
+
}))));
|
|
1225
|
+
const two = screen.getByRole('tab', {
|
|
1226
|
+
name: 'two'
|
|
1227
|
+
});
|
|
1228
|
+
expect(two.parentElement).toHaveAttribute('data-selected', 'false');
|
|
1229
|
+
onChange.mockClear();
|
|
1230
|
+
fireEvent.click(two);
|
|
1231
|
+
expect(onChange).toHaveBeenCalledWith(expect.objectContaining({
|
|
1232
|
+
value: 'two'
|
|
1233
|
+
}), expect.anything());
|
|
1234
|
+
expect(two.parentElement).toHaveAttribute('data-selected', 'true');
|
|
1235
|
+
});
|
|
1236
|
+
test('a data-driven item forwards renderAction, with the slot state', () => {
|
|
1237
|
+
render( /*#__PURE__*/React.createElement(Tabs, {
|
|
1238
|
+
uniqueId: "tabs",
|
|
1239
|
+
selectedValue: "a"
|
|
1240
|
+
}, /*#__PURE__*/React.createElement(TabList, {
|
|
1241
|
+
ariaLabel: "Cities",
|
|
1242
|
+
minVisibleTabs: ITEMS.length,
|
|
1243
|
+
items: ITEMS.map(item => item.value === 'a' ? { ...item,
|
|
1244
|
+
renderAction: ({
|
|
1245
|
+
isSelected
|
|
1246
|
+
}) => /*#__PURE__*/React.createElement("span", null, `action-${isSelected}`)
|
|
1247
|
+
} : item)
|
|
1248
|
+
})));
|
|
1249
|
+
const tab = screen.getByRole('tab', {
|
|
1250
|
+
name: 'Alpha'
|
|
1251
|
+
});
|
|
1252
|
+
const action = screen.getByText('action-true');
|
|
1253
|
+
expect(tab.contains(action)).toBe(false);
|
|
1254
|
+
expect(tab.parentElement.contains(action)).toBe(true);
|
|
1255
|
+
});
|
|
1256
|
+
test('selected and disabled styles also target the action wrapper', () => {
|
|
1257
|
+
const css = readStylesheet();
|
|
1258
|
+
['tab', 'tabElevated', 'tabSpaced', 'tabDotted'].forEach(selector => {
|
|
1259
|
+
expect(css).toMatch(new RegExp(`\\.${selector}\\[data-selected='true'\\]`));
|
|
1260
|
+
});
|
|
1261
|
+
expect(css).toMatch(/\.tab\[data-disabled='true'\]/);
|
|
1262
|
+
});
|
|
1263
|
+
test('the data-driven list clips overflow only while the more menu is portalled', () => {
|
|
1264
|
+
const {
|
|
1265
|
+
rerender
|
|
1266
|
+
} = render( /*#__PURE__*/React.createElement(Tabs, {
|
|
1267
|
+
uniqueId: "tabs"
|
|
1268
|
+
}, /*#__PURE__*/React.createElement(TabList, {
|
|
1269
|
+
ariaLabel: "Cities",
|
|
1270
|
+
items: ITEMS
|
|
1271
|
+
})));
|
|
1272
|
+
expect(screen.getByRole('tablist').className).toContain('d-overflow-hidden');
|
|
1273
|
+
/* An inline (absolutely positioned) menu renders inside the list, so a
|
|
1274
|
+
* clipping list would hide it. */
|
|
1275
|
+
|
|
1276
|
+
rerender( /*#__PURE__*/React.createElement(Tabs, {
|
|
1277
|
+
uniqueId: "tabs"
|
|
1278
|
+
}, /*#__PURE__*/React.createElement(TabList, {
|
|
1279
|
+
ariaLabel: "Cities",
|
|
1280
|
+
items: ITEMS,
|
|
1281
|
+
customProps: {
|
|
1282
|
+
popup: {
|
|
1283
|
+
isAbsolutePositioningNeeded: true
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
})));
|
|
1287
|
+
expect(screen.getByRole('tablist').className).not.toContain('d-overflow-hidden');
|
|
1288
|
+
});
|
|
1102
1289
|
});
|
|
@@ -1880,7 +1880,7 @@ exports[`Tab - Snapshot Render the open more menu with Popup HOC options forward
|
|
|
1880
1880
|
<div
|
|
1881
1881
|
aria-label="Cities"
|
|
1882
1882
|
aria-orientation="horizontal"
|
|
1883
|
-
class="d-flex d-flex-row d-items-stretch d-flex-nowrap
|
|
1883
|
+
class="d-flex d-flex-row d-items-stretch d-flex-nowrap list d-relative d-min-w-0 d-border-solid listTop"
|
|
1884
1884
|
data-a11y-focus-scope="true"
|
|
1885
1885
|
data-id="dotTabList"
|
|
1886
1886
|
data-test-id="dotTabList"
|
|
@@ -35,8 +35,30 @@
|
|
|
35
35
|
background-color var(--zd_transition2) ease;
|
|
36
36
|
background-color: transparent;
|
|
37
37
|
}
|
|
38
|
+
|
|
39
|
+
/* A trigger inside an action wrapper: the wrapper carries the visual tab. */
|
|
40
|
+
.tabTrigger {
|
|
41
|
+
appearance: none;
|
|
42
|
+
font: inherit;
|
|
43
|
+
color: inherit;
|
|
44
|
+
margin: 0 ;
|
|
45
|
+
padding: 0 ;
|
|
46
|
+
border-width: 0;
|
|
47
|
+
cursor: inherit;
|
|
48
|
+
background-color: transparent;
|
|
49
|
+
}
|
|
38
50
|
/* stylelint-enable @zohodesk/use-common-class */
|
|
39
51
|
|
|
52
|
+
.tabTrigger::after {
|
|
53
|
+
content: '';
|
|
54
|
+
position: absolute;
|
|
55
|
+
inset: 0 ;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.tabAction {
|
|
59
|
+
z-index: 1;
|
|
60
|
+
}
|
|
61
|
+
|
|
40
62
|
.moreBox {
|
|
41
63
|
min-inline-size: var(--zd_size160) ;
|
|
42
64
|
}
|
|
@@ -76,12 +98,17 @@
|
|
|
76
98
|
color: var(--zdt_v1_tab_text_hover);
|
|
77
99
|
}
|
|
78
100
|
|
|
79
|
-
.tab[aria-selected='true']
|
|
101
|
+
.tab[aria-selected='true'],
|
|
102
|
+
.tab[data-selected='true'] {
|
|
80
103
|
color: var(--zdt_v1_tab_text_active);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.tab[aria-selected='true'], .tab[data-selected='true'] {
|
|
81
107
|
border-color: var(--zdt_v1_tab_indicator_active);
|
|
82
108
|
}
|
|
83
109
|
|
|
84
110
|
.tab:focus-visible,
|
|
111
|
+
.tabTrigger:focus-visible::after,
|
|
85
112
|
.more:focus-visible,
|
|
86
113
|
.panel:focus-visible {
|
|
87
114
|
outline: 2px solid var(--zdt_v1_tab_indicator_active);
|
|
@@ -199,8 +226,12 @@
|
|
|
199
226
|
background-color: var(--zdt_v1_tab_preset_bg_hover);
|
|
200
227
|
}
|
|
201
228
|
|
|
202
|
-
.tabElevated[aria-selected='true']
|
|
229
|
+
.tabElevated[aria-selected='true'],
|
|
230
|
+
.tabElevated[data-selected='true'] {
|
|
203
231
|
color: var(--zdt_v1_tab_preset_text_active);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
.tabElevated[aria-selected='true'], .tabElevated[data-selected='true'] {
|
|
204
235
|
border-color: var(--zdt_v1_tab_preset_indicator_active);
|
|
205
236
|
}
|
|
206
237
|
|
|
@@ -245,8 +276,12 @@
|
|
|
245
276
|
background-color: transparent;
|
|
246
277
|
}
|
|
247
278
|
|
|
248
|
-
.tabSpaced[aria-selected='true']
|
|
279
|
+
.tabSpaced[aria-selected='true'],
|
|
280
|
+
.tabSpaced[data-selected='true'] {
|
|
249
281
|
color: var(--zdt_v1_tab_preset_text_hover);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
.tabSpaced[aria-selected='true'], .tabSpaced[data-selected='true'] {
|
|
250
285
|
border-color: var(--zdt_v1_tab_preset_indicator_active);
|
|
251
286
|
}
|
|
252
287
|
|
|
@@ -292,8 +327,12 @@
|
|
|
292
327
|
background-color: transparent;
|
|
293
328
|
}
|
|
294
329
|
|
|
295
|
-
.tabDotted[aria-selected='true']
|
|
330
|
+
.tabDotted[aria-selected='true'],
|
|
331
|
+
.tabDotted[data-selected='true'] {
|
|
296
332
|
color: var(--zdt_v1_tab_preset_text_active);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
.tabDotted[aria-selected='true'], .tabDotted[data-selected='true'] {
|
|
297
336
|
border-color: var(--zdt_v1_tab_preset_delta_indicator_active);
|
|
298
337
|
}
|
|
299
338
|
|
|
@@ -351,10 +390,12 @@
|
|
|
351
390
|
/* ---------- Disabled (always last) ---------- */
|
|
352
391
|
|
|
353
392
|
.tab[aria-disabled='true'],
|
|
354
|
-
.tab[aria-disabled='true']:hover
|
|
393
|
+
.tab[aria-disabled='true']:hover,
|
|
394
|
+
.tab[data-disabled='true'],
|
|
395
|
+
.tab[data-disabled='true']:hover {
|
|
355
396
|
color: var(--zdt_v1_tab_text_disabled);
|
|
356
397
|
}
|
|
357
398
|
|
|
358
|
-
.tab[aria-disabled='true'], .tab[aria-disabled='true']:hover {
|
|
399
|
+
.tab[aria-disabled='true'], .tab[aria-disabled='true']:hover, .tab[data-disabled='true'], .tab[data-disabled='true']:hover {
|
|
359
400
|
background-color: transparent;
|
|
360
401
|
}
|
package/es/v1/Tab/css/tab.cva.js
CHANGED
|
@@ -97,6 +97,15 @@ const tabSlots = csv({
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
},
|
|
100
|
+
// With `renderAction` the `tab` slot styles a wrapper; the role="tab"
|
|
101
|
+
// trigger inside it is flush, and its ::after stretches over the wrapper
|
|
102
|
+
// so the whole tab stays clickable.
|
|
103
|
+
tabTrigger: {
|
|
104
|
+
base: [style.tabTrigger, 'd-min-w-0', 'd-max-w-full', 'd-no-underline', 'd-select-none']
|
|
105
|
+
},
|
|
106
|
+
tabAction: {
|
|
107
|
+
base: [style.tabAction, 'd-relative', 'd-inline-flex', 'd-items-center']
|
|
108
|
+
},
|
|
100
109
|
content: {
|
|
101
110
|
// `d-flex` comes from the FlexContainer that renders this slot.
|
|
102
111
|
base: ['d-min-w-0', 'd-max-w-full'],
|
|
@@ -5,6 +5,8 @@ const renderableType = PropTypes.oneOfType([PropTypes.node, PropTypes.func]);
|
|
|
5
5
|
const classType = PropTypes.string;
|
|
6
6
|
const tabSlotClasses = {
|
|
7
7
|
tab: classType,
|
|
8
|
+
tabTrigger: classType,
|
|
9
|
+
tabAction: classType,
|
|
8
10
|
content: classType,
|
|
9
11
|
iconBox: classType,
|
|
10
12
|
tabText: classType
|
|
@@ -102,6 +104,10 @@ const tabItemShape = PropTypes.shape({
|
|
|
102
104
|
renderIcon: renderableType,
|
|
103
105
|
renderBefore: renderableType,
|
|
104
106
|
renderAfter: renderableType,
|
|
107
|
+
|
|
108
|
+
/* Rendered beside the tab button, outside it; not shown in the more menu. */
|
|
109
|
+
renderAction: renderableType,
|
|
110
|
+
customClass: PropTypes.shape(tabSlotClasses),
|
|
105
111
|
customId: PropTypes.string,
|
|
106
112
|
testId: PropTypes.string,
|
|
107
113
|
dataSelectorId: PropTypes.string
|
|
@@ -148,6 +154,11 @@ export const Tab_propTypes = {
|
|
|
148
154
|
renderIcon: renderableType,
|
|
149
155
|
renderBefore: renderableType,
|
|
150
156
|
renderAfter: renderableType,
|
|
157
|
+
|
|
158
|
+
/* Interactive node rendered beside the role="tab" button, outside it. The
|
|
159
|
+
* `tab` slot then styles a wrapper that also carries customId, testId,
|
|
160
|
+
* dataSelectorId and tourId. */
|
|
161
|
+
renderAction: renderableType,
|
|
151
162
|
onClick: PropTypes.func,
|
|
152
163
|
getRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
|
153
164
|
customClass: PropTypes.shape(tabSlotClasses),
|
package/lib/v1/Tab/Tab.js
CHANGED
|
@@ -55,6 +55,7 @@ var Tab = function Tab(props) {
|
|
|
55
55
|
renderIcon = props.renderIcon,
|
|
56
56
|
renderBefore = props.renderBefore,
|
|
57
57
|
renderAfter = props.renderAfter,
|
|
58
|
+
renderAction = props.renderAction,
|
|
58
59
|
onClick = props.onClick,
|
|
59
60
|
getRef = props.getRef,
|
|
60
61
|
customClass = props.customClass,
|
|
@@ -82,6 +83,9 @@ var Tab = function Tab(props) {
|
|
|
82
83
|
textTransformFromGroup = _useTabsStyle.textTransform,
|
|
83
84
|
textTruncateFromGroup = _useTabsStyle.textTruncate;
|
|
84
85
|
|
|
86
|
+
var _useTabsData = (0, _core.useTabsData)('Tab'),
|
|
87
|
+
selectedValue = _useTabsData.selectedValue;
|
|
88
|
+
|
|
85
89
|
var textTransform = textTransformFromGroup || _constants.TEXT_TRANSFORM.CAPITAL;
|
|
86
90
|
var textTruncate = textTruncateFromGroup || _constants.TEXT_TRUNCATE.CLAMP;
|
|
87
91
|
var isTextOnly = labelStyle === _constants.LABEL_STYLE.TEXT;
|
|
@@ -106,19 +110,23 @@ var Tab = function Tab(props) {
|
|
|
106
110
|
}
|
|
107
111
|
|
|
108
112
|
var classes = getClasses(styleOverrides);
|
|
109
|
-
var isAnchor = !!href;
|
|
113
|
+
var isAnchor = !!href; // With an action the visual tab becomes a wrapper around the role="tab"
|
|
114
|
+
// trigger, so an interactive action never nests inside the <button>.
|
|
115
|
+
|
|
116
|
+
var hasAction = (0, _renderNode.isRenderable)(renderAction);
|
|
110
117
|
var elementProps = (0, _mergeProps["default"])({
|
|
111
|
-
className: classes.tab,
|
|
118
|
+
className: hasAction ? classes.tabTrigger : classes.tab,
|
|
112
119
|
href: isAnchor && !isDisabled ? href : undefined,
|
|
113
120
|
target: isAnchor ? target : undefined,
|
|
114
121
|
rel: isAnchor ? rel : undefined,
|
|
115
|
-
'data-tour': tourId,
|
|
122
|
+
'data-tour': hasAction ? undefined : tourId,
|
|
116
123
|
'aria-label': accessibleName,
|
|
117
124
|
'data-title': title
|
|
118
125
|
}, {
|
|
119
126
|
onClick: onClick
|
|
120
127
|
}, tabAttributes, a11yAttributes);
|
|
121
|
-
|
|
128
|
+
|
|
129
|
+
var trigger = /*#__PURE__*/_react["default"].createElement(_core.Tab, _extends({
|
|
122
130
|
value: value,
|
|
123
131
|
isDisabled: isDisabled,
|
|
124
132
|
isAnchor: isAnchor,
|
|
@@ -127,9 +135,9 @@ var Tab = function Tab(props) {
|
|
|
127
135
|
alignItems: "center",
|
|
128
136
|
justifyContent: justifyContent
|
|
129
137
|
}, elementProps, {
|
|
130
|
-
customId: customId,
|
|
131
|
-
testId: testId,
|
|
132
|
-
"data-selector-id": dataSelectorId
|
|
138
|
+
customId: hasAction ? undefined : customId,
|
|
139
|
+
testId: hasAction ? undefined : testId,
|
|
140
|
+
"data-selector-id": hasAction ? undefined : dataSelectorId
|
|
133
141
|
}), function (_ref) {
|
|
134
142
|
var isSelected = _ref.isSelected;
|
|
135
143
|
var slot = {
|
|
@@ -167,6 +175,37 @@ var Tab = function Tab(props) {
|
|
|
167
175
|
$tagAttributes_container: tabTextAttributes
|
|
168
176
|
}), text) : null, children, (0, _renderNode.isRenderable)(renderAfter) ? (0, _renderNode["default"])(renderAfter, slot) : null);
|
|
169
177
|
});
|
|
178
|
+
|
|
179
|
+
if (!hasAction) {
|
|
180
|
+
return trigger;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
var isSelected = value === selectedValue;
|
|
184
|
+
var actionSlot = {
|
|
185
|
+
value: value,
|
|
186
|
+
isSelected: isSelected,
|
|
187
|
+
isDisabled: isDisabled
|
|
188
|
+
};
|
|
189
|
+
return /*#__PURE__*/_react["default"].createElement(_FlexContainer["default"], {
|
|
190
|
+
as: "span",
|
|
191
|
+
display: "inlineFlex",
|
|
192
|
+
alignItems: "center",
|
|
193
|
+
justifyContent: justifyContent,
|
|
194
|
+
customClass: classes.tab,
|
|
195
|
+
customId: customId,
|
|
196
|
+
testId: testId,
|
|
197
|
+
customAttributes: {
|
|
198
|
+
role: 'presentation',
|
|
199
|
+
'data-selected': String(isSelected),
|
|
200
|
+
'data-disabled': String(!!isDisabled),
|
|
201
|
+
'data-tour': tourId,
|
|
202
|
+
'data-selector-id': dataSelectorId
|
|
203
|
+
}
|
|
204
|
+
}, trigger, /*#__PURE__*/_react["default"].createElement(_FlexItem["default"], {
|
|
205
|
+
as: "span",
|
|
206
|
+
shrink: "0",
|
|
207
|
+
customClass: classes.tabAction
|
|
208
|
+
}, (0, _renderNode["default"])(renderAction, actionSlot)));
|
|
170
209
|
};
|
|
171
210
|
|
|
172
211
|
var _default = Tab;
|
package/lib/v1/Tab/TabList.js
CHANGED
|
@@ -89,11 +89,20 @@ var TabList = function TabList(props) {
|
|
|
89
89
|
return _objectSpread(_objectSpread({}, styleContext), {}, {
|
|
90
90
|
hasOverflow: isDataDriven
|
|
91
91
|
});
|
|
92
|
-
}, [styleContext, isDataDriven]);
|
|
93
|
-
|
|
92
|
+
}, [styleContext, isDataDriven]); // An inline (absolutely positioned) more menu renders inside the list, so
|
|
93
|
+
// clipping the list would hide it; a portalled menu escapes the clip.
|
|
94
|
+
|
|
95
|
+
var isMoreMenuInline = !!popupOptions.isAbsolutePositioningNeeded;
|
|
96
|
+
var scroll = hasScroll ? orientation === _constants2.ORIENTATION.VERTICAL ? 'vertical' : 'horizontal' : isDataDriven && !isMoreMenuInline ? 'hidden' : undefined;
|
|
97
|
+
|
|
98
|
+
var getClassSignature = function getClassSignature(itemClass) {
|
|
99
|
+
return itemClass ? Object.keys(itemClass).map(function (slot) {
|
|
100
|
+
return "".concat(slot, ":").concat(itemClass[slot] || '');
|
|
101
|
+
}).join(',') : '';
|
|
102
|
+
};
|
|
94
103
|
|
|
95
104
|
var itemsSignature = "".concat(labelStyle || '', "\x01").concat(position || '', "\x01") + (items || _constants.DUMMY_ARRAY).map(function (item) {
|
|
96
|
-
return "".concat(item.value, "|").concat(item.text || '', "|").concat(item.iconName || '', "|").concat(item.isDisabled ? 1 : 0, "|").concat(item.renderBefore ? 1 : 0, "|").concat(item.renderAfter ? 1 : 0);
|
|
105
|
+
return "".concat(item.value, "|").concat(item.text || '', "|").concat(item.iconName || '', "|").concat(item.isDisabled ? 1 : 0, "|").concat(item.renderBefore ? 1 : 0, "|").concat(item.renderAfter ? 1 : 0, "|").concat(item.renderAction ? 1 : 0, "|").concat(getClassSignature(item.customClass));
|
|
97
106
|
}).join("\0");
|
|
98
107
|
|
|
99
108
|
var dataList = (0, _react.useMemo)(function () {
|
|
@@ -154,6 +163,8 @@ var TabList = function TabList(props) {
|
|
|
154
163
|
renderIcon: item.renderIcon,
|
|
155
164
|
renderBefore: item.renderBefore,
|
|
156
165
|
renderAfter: item.renderAfter,
|
|
166
|
+
renderAction: item.renderAction,
|
|
167
|
+
customClass: item.customClass,
|
|
157
168
|
customId: item.customId,
|
|
158
169
|
testId: item.testId,
|
|
159
170
|
dataSelectorId: item.dataSelectorId
|
|
@@ -1203,4 +1203,218 @@ describe('Tab - Behaviour', function () {
|
|
|
1203
1203
|
|
|
1204
1204
|
expect(document.querySelector('input[name="search"]')).toBeNull();
|
|
1205
1205
|
});
|
|
1206
|
+
});
|
|
1207
|
+
/*
|
|
1208
|
+
* Per-item customClass and renderAction exist for the ticket detail-view
|
|
1209
|
+
* subtab strip: a custom-lookup tab caps its own width, and the conversation
|
|
1210
|
+
* tab carries an interactive view-type menu that must not nest inside the
|
|
1211
|
+
* <button role="tab">.
|
|
1212
|
+
*/
|
|
1213
|
+
|
|
1214
|
+
describe('Tab - Item customClass, renderAction and an inline more menu', function () {
|
|
1215
|
+
test('a data-driven item customClass lands on that tab only', function () {
|
|
1216
|
+
(0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Tabs["default"], {
|
|
1217
|
+
uniqueId: "tabs"
|
|
1218
|
+
}, /*#__PURE__*/_react["default"].createElement(_TabList["default"], {
|
|
1219
|
+
ariaLabel: "Cities",
|
|
1220
|
+
minVisibleTabs: ITEMS.length,
|
|
1221
|
+
items: ITEMS.map(function (item) {
|
|
1222
|
+
return item.value === 'b' ? _objectSpread(_objectSpread({}, item), {}, {
|
|
1223
|
+
customClass: {
|
|
1224
|
+
tab: 'capped-tab'
|
|
1225
|
+
}
|
|
1226
|
+
}) : item;
|
|
1227
|
+
})
|
|
1228
|
+
})));
|
|
1229
|
+
expect(_react2.screen.getByRole('tab', {
|
|
1230
|
+
name: 'Bravo'
|
|
1231
|
+
}).className).toContain('capped-tab');
|
|
1232
|
+
expect(_react2.screen.getByRole('tab', {
|
|
1233
|
+
name: 'Alpha'
|
|
1234
|
+
}).className).not.toContain('capped-tab');
|
|
1235
|
+
expect(_react2.screen.getByRole('tab', {
|
|
1236
|
+
name: 'Charlie'
|
|
1237
|
+
}).className).not.toContain('capped-tab');
|
|
1238
|
+
});
|
|
1239
|
+
test('changing only an item customClass re-renders that tab', function () {
|
|
1240
|
+
var renderList = function renderList(tabClass) {
|
|
1241
|
+
return /*#__PURE__*/_react["default"].createElement(_Tabs["default"], {
|
|
1242
|
+
uniqueId: "tabs"
|
|
1243
|
+
}, /*#__PURE__*/_react["default"].createElement(_TabList["default"], {
|
|
1244
|
+
ariaLabel: "Cities",
|
|
1245
|
+
minVisibleTabs: ITEMS.length,
|
|
1246
|
+
items: ITEMS.map(function (item) {
|
|
1247
|
+
return item.value === 'a' ? _objectSpread(_objectSpread({}, item), {}, {
|
|
1248
|
+
customClass: {
|
|
1249
|
+
tab: tabClass
|
|
1250
|
+
}
|
|
1251
|
+
}) : item;
|
|
1252
|
+
})
|
|
1253
|
+
}));
|
|
1254
|
+
};
|
|
1255
|
+
|
|
1256
|
+
var _render54 = (0, _react2.render)(renderList('first-class')),
|
|
1257
|
+
rerender = _render54.rerender;
|
|
1258
|
+
|
|
1259
|
+
rerender(renderList('second-class'));
|
|
1260
|
+
|
|
1261
|
+
var tab = _react2.screen.getByRole('tab', {
|
|
1262
|
+
name: 'Alpha'
|
|
1263
|
+
});
|
|
1264
|
+
|
|
1265
|
+
expect(tab.className).toContain('second-class');
|
|
1266
|
+
expect(tab.className).not.toContain('first-class');
|
|
1267
|
+
});
|
|
1268
|
+
test('renderAction renders beside the tab button, never inside it', function () {
|
|
1269
|
+
(0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Tabs["default"], {
|
|
1270
|
+
uniqueId: "tabs",
|
|
1271
|
+
selectedValue: "one"
|
|
1272
|
+
}, /*#__PURE__*/_react["default"].createElement(_TabList["default"], {
|
|
1273
|
+
ariaLabel: "Cities"
|
|
1274
|
+
}, /*#__PURE__*/_react["default"].createElement(_Tab["default"], {
|
|
1275
|
+
value: "one",
|
|
1276
|
+
text: "one",
|
|
1277
|
+
customId: "one_Tab",
|
|
1278
|
+
renderAction: function renderAction() {
|
|
1279
|
+
return /*#__PURE__*/_react["default"].createElement("button", {
|
|
1280
|
+
type: "button"
|
|
1281
|
+
}, "view");
|
|
1282
|
+
}
|
|
1283
|
+
}), /*#__PURE__*/_react["default"].createElement(_Tab["default"], {
|
|
1284
|
+
value: "two",
|
|
1285
|
+
text: "two"
|
|
1286
|
+
}))));
|
|
1287
|
+
|
|
1288
|
+
var tab = _react2.screen.getByRole('tab', {
|
|
1289
|
+
name: 'one'
|
|
1290
|
+
});
|
|
1291
|
+
|
|
1292
|
+
var action = _react2.screen.getByRole('button', {
|
|
1293
|
+
name: 'view'
|
|
1294
|
+
});
|
|
1295
|
+
|
|
1296
|
+
expect(tab.contains(action)).toBe(false);
|
|
1297
|
+
expect(tab.querySelector('button')).toBeNull();
|
|
1298
|
+
/* The wrapper is the visual tab: it holds both, carries the state and the ids. */
|
|
1299
|
+
|
|
1300
|
+
var wrapper = tab.parentElement;
|
|
1301
|
+
expect(wrapper.contains(action)).toBe(true);
|
|
1302
|
+
expect(wrapper).toHaveAttribute('data-selected', 'true');
|
|
1303
|
+
expect(wrapper).toHaveAttribute('data-id', 'one_Tab');
|
|
1304
|
+
expect(tab).not.toHaveAttribute('data-id', 'one_Tab');
|
|
1305
|
+
expect(wrapper.className).toContain('tab');
|
|
1306
|
+
expect(tab.className).toContain('tabTrigger');
|
|
1307
|
+
/* The wrapper is the direct child the adaptive renderer measures. */
|
|
1308
|
+
|
|
1309
|
+
expect(wrapper.parentElement).toBe(_react2.screen.getByRole('tablist'));
|
|
1310
|
+
});
|
|
1311
|
+
test('without renderAction the tab DOM is unchanged', function () {
|
|
1312
|
+
(0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Tabs["default"], {
|
|
1313
|
+
uniqueId: "tabs"
|
|
1314
|
+
}, /*#__PURE__*/_react["default"].createElement(_TabList["default"], {
|
|
1315
|
+
ariaLabel: "Cities"
|
|
1316
|
+
}, /*#__PURE__*/_react["default"].createElement(_Tab["default"], {
|
|
1317
|
+
value: "one",
|
|
1318
|
+
text: "one"
|
|
1319
|
+
}))));
|
|
1320
|
+
|
|
1321
|
+
var tab = _react2.screen.getByRole('tab', {
|
|
1322
|
+
name: 'one'
|
|
1323
|
+
});
|
|
1324
|
+
|
|
1325
|
+
expect(tab.parentElement).toBe(_react2.screen.getByRole('tablist'));
|
|
1326
|
+
expect(tab.className).not.toContain('tabTrigger');
|
|
1327
|
+
});
|
|
1328
|
+
test('the wrapper follows selection and the trigger still selects on click', function () {
|
|
1329
|
+
var onChange = jest.fn();
|
|
1330
|
+
(0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Tabs["default"], {
|
|
1331
|
+
uniqueId: "tabs",
|
|
1332
|
+
defaultValue: "one",
|
|
1333
|
+
onChange: onChange
|
|
1334
|
+
}, /*#__PURE__*/_react["default"].createElement(_TabList["default"], {
|
|
1335
|
+
ariaLabel: "Cities"
|
|
1336
|
+
}, /*#__PURE__*/_react["default"].createElement(_Tab["default"], {
|
|
1337
|
+
value: "one",
|
|
1338
|
+
text: "one"
|
|
1339
|
+
}), /*#__PURE__*/_react["default"].createElement(_Tab["default"], {
|
|
1340
|
+
value: "two",
|
|
1341
|
+
text: "two",
|
|
1342
|
+
renderAction: function renderAction() {
|
|
1343
|
+
return /*#__PURE__*/_react["default"].createElement("span", null, "action");
|
|
1344
|
+
}
|
|
1345
|
+
}))));
|
|
1346
|
+
|
|
1347
|
+
var two = _react2.screen.getByRole('tab', {
|
|
1348
|
+
name: 'two'
|
|
1349
|
+
});
|
|
1350
|
+
|
|
1351
|
+
expect(two.parentElement).toHaveAttribute('data-selected', 'false');
|
|
1352
|
+
onChange.mockClear();
|
|
1353
|
+
|
|
1354
|
+
_react2.fireEvent.click(two);
|
|
1355
|
+
|
|
1356
|
+
expect(onChange).toHaveBeenCalledWith(expect.objectContaining({
|
|
1357
|
+
value: 'two'
|
|
1358
|
+
}), expect.anything());
|
|
1359
|
+
expect(two.parentElement).toHaveAttribute('data-selected', 'true');
|
|
1360
|
+
});
|
|
1361
|
+
test('a data-driven item forwards renderAction, with the slot state', function () {
|
|
1362
|
+
(0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Tabs["default"], {
|
|
1363
|
+
uniqueId: "tabs",
|
|
1364
|
+
selectedValue: "a"
|
|
1365
|
+
}, /*#__PURE__*/_react["default"].createElement(_TabList["default"], {
|
|
1366
|
+
ariaLabel: "Cities",
|
|
1367
|
+
minVisibleTabs: ITEMS.length,
|
|
1368
|
+
items: ITEMS.map(function (item) {
|
|
1369
|
+
return item.value === 'a' ? _objectSpread(_objectSpread({}, item), {}, {
|
|
1370
|
+
renderAction: function renderAction(_ref6) {
|
|
1371
|
+
var isSelected = _ref6.isSelected;
|
|
1372
|
+
return /*#__PURE__*/_react["default"].createElement("span", null, "action-".concat(isSelected));
|
|
1373
|
+
}
|
|
1374
|
+
}) : item;
|
|
1375
|
+
})
|
|
1376
|
+
})));
|
|
1377
|
+
|
|
1378
|
+
var tab = _react2.screen.getByRole('tab', {
|
|
1379
|
+
name: 'Alpha'
|
|
1380
|
+
});
|
|
1381
|
+
|
|
1382
|
+
var action = _react2.screen.getByText('action-true');
|
|
1383
|
+
|
|
1384
|
+
expect(tab.contains(action)).toBe(false);
|
|
1385
|
+
expect(tab.parentElement.contains(action)).toBe(true);
|
|
1386
|
+
});
|
|
1387
|
+
test('selected and disabled styles also target the action wrapper', function () {
|
|
1388
|
+
var css = readStylesheet();
|
|
1389
|
+
['tab', 'tabElevated', 'tabSpaced', 'tabDotted'].forEach(function (selector) {
|
|
1390
|
+
expect(css).toMatch(new RegExp("\\.".concat(selector, "\\[data-selected='true'\\]")));
|
|
1391
|
+
});
|
|
1392
|
+
expect(css).toMatch(/\.tab\[data-disabled='true'\]/);
|
|
1393
|
+
});
|
|
1394
|
+
test('the data-driven list clips overflow only while the more menu is portalled', function () {
|
|
1395
|
+
var _render55 = (0, _react2.render)( /*#__PURE__*/_react["default"].createElement(_Tabs["default"], {
|
|
1396
|
+
uniqueId: "tabs"
|
|
1397
|
+
}, /*#__PURE__*/_react["default"].createElement(_TabList["default"], {
|
|
1398
|
+
ariaLabel: "Cities",
|
|
1399
|
+
items: ITEMS
|
|
1400
|
+
}))),
|
|
1401
|
+
rerender = _render55.rerender;
|
|
1402
|
+
|
|
1403
|
+
expect(_react2.screen.getByRole('tablist').className).toContain('d-overflow-hidden');
|
|
1404
|
+
/* An inline (absolutely positioned) menu renders inside the list, so a
|
|
1405
|
+
* clipping list would hide it. */
|
|
1406
|
+
|
|
1407
|
+
rerender( /*#__PURE__*/_react["default"].createElement(_Tabs["default"], {
|
|
1408
|
+
uniqueId: "tabs"
|
|
1409
|
+
}, /*#__PURE__*/_react["default"].createElement(_TabList["default"], {
|
|
1410
|
+
ariaLabel: "Cities",
|
|
1411
|
+
items: ITEMS,
|
|
1412
|
+
customProps: {
|
|
1413
|
+
popup: {
|
|
1414
|
+
isAbsolutePositioningNeeded: true
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
})));
|
|
1418
|
+
expect(_react2.screen.getByRole('tablist').className).not.toContain('d-overflow-hidden');
|
|
1419
|
+
});
|
|
1206
1420
|
});
|
|
@@ -1880,7 +1880,7 @@ exports[`Tab - Snapshot Render the open more menu with Popup HOC options forward
|
|
|
1880
1880
|
<div
|
|
1881
1881
|
aria-label="Cities"
|
|
1882
1882
|
aria-orientation="horizontal"
|
|
1883
|
-
class="d-flex d-flex-row d-items-stretch d-flex-nowrap
|
|
1883
|
+
class="d-flex d-flex-row d-items-stretch d-flex-nowrap list d-relative d-min-w-0 d-border-solid listTop"
|
|
1884
1884
|
data-a11y-focus-scope="true"
|
|
1885
1885
|
data-id="dotTabList"
|
|
1886
1886
|
data-test-id="dotTabList"
|
|
@@ -35,8 +35,30 @@
|
|
|
35
35
|
background-color var(--zd_transition2) ease;
|
|
36
36
|
background-color: transparent;
|
|
37
37
|
}
|
|
38
|
+
|
|
39
|
+
/* A trigger inside an action wrapper: the wrapper carries the visual tab. */
|
|
40
|
+
.tabTrigger {
|
|
41
|
+
appearance: none;
|
|
42
|
+
font: inherit;
|
|
43
|
+
color: inherit;
|
|
44
|
+
margin: 0 ;
|
|
45
|
+
padding: 0 ;
|
|
46
|
+
border-width: 0;
|
|
47
|
+
cursor: inherit;
|
|
48
|
+
background-color: transparent;
|
|
49
|
+
}
|
|
38
50
|
/* stylelint-enable @zohodesk/use-common-class */
|
|
39
51
|
|
|
52
|
+
.tabTrigger::after {
|
|
53
|
+
content: '';
|
|
54
|
+
position: absolute;
|
|
55
|
+
inset: 0 ;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.tabAction {
|
|
59
|
+
z-index: 1;
|
|
60
|
+
}
|
|
61
|
+
|
|
40
62
|
.moreBox {
|
|
41
63
|
min-inline-size: var(--zd_size160) ;
|
|
42
64
|
}
|
|
@@ -76,12 +98,17 @@
|
|
|
76
98
|
color: var(--zdt_v1_tab_text_hover);
|
|
77
99
|
}
|
|
78
100
|
|
|
79
|
-
.tab[aria-selected='true']
|
|
101
|
+
.tab[aria-selected='true'],
|
|
102
|
+
.tab[data-selected='true'] {
|
|
80
103
|
color: var(--zdt_v1_tab_text_active);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.tab[aria-selected='true'], .tab[data-selected='true'] {
|
|
81
107
|
border-color: var(--zdt_v1_tab_indicator_active);
|
|
82
108
|
}
|
|
83
109
|
|
|
84
110
|
.tab:focus-visible,
|
|
111
|
+
.tabTrigger:focus-visible::after,
|
|
85
112
|
.more:focus-visible,
|
|
86
113
|
.panel:focus-visible {
|
|
87
114
|
outline: 2px solid var(--zdt_v1_tab_indicator_active);
|
|
@@ -199,8 +226,12 @@
|
|
|
199
226
|
background-color: var(--zdt_v1_tab_preset_bg_hover);
|
|
200
227
|
}
|
|
201
228
|
|
|
202
|
-
.tabElevated[aria-selected='true']
|
|
229
|
+
.tabElevated[aria-selected='true'],
|
|
230
|
+
.tabElevated[data-selected='true'] {
|
|
203
231
|
color: var(--zdt_v1_tab_preset_text_active);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
.tabElevated[aria-selected='true'], .tabElevated[data-selected='true'] {
|
|
204
235
|
border-color: var(--zdt_v1_tab_preset_indicator_active);
|
|
205
236
|
}
|
|
206
237
|
|
|
@@ -245,8 +276,12 @@
|
|
|
245
276
|
background-color: transparent;
|
|
246
277
|
}
|
|
247
278
|
|
|
248
|
-
.tabSpaced[aria-selected='true']
|
|
279
|
+
.tabSpaced[aria-selected='true'],
|
|
280
|
+
.tabSpaced[data-selected='true'] {
|
|
249
281
|
color: var(--zdt_v1_tab_preset_text_hover);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
.tabSpaced[aria-selected='true'], .tabSpaced[data-selected='true'] {
|
|
250
285
|
border-color: var(--zdt_v1_tab_preset_indicator_active);
|
|
251
286
|
}
|
|
252
287
|
|
|
@@ -292,8 +327,12 @@
|
|
|
292
327
|
background-color: transparent;
|
|
293
328
|
}
|
|
294
329
|
|
|
295
|
-
.tabDotted[aria-selected='true']
|
|
330
|
+
.tabDotted[aria-selected='true'],
|
|
331
|
+
.tabDotted[data-selected='true'] {
|
|
296
332
|
color: var(--zdt_v1_tab_preset_text_active);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
.tabDotted[aria-selected='true'], .tabDotted[data-selected='true'] {
|
|
297
336
|
border-color: var(--zdt_v1_tab_preset_delta_indicator_active);
|
|
298
337
|
}
|
|
299
338
|
|
|
@@ -351,10 +390,12 @@
|
|
|
351
390
|
/* ---------- Disabled (always last) ---------- */
|
|
352
391
|
|
|
353
392
|
.tab[aria-disabled='true'],
|
|
354
|
-
.tab[aria-disabled='true']:hover
|
|
393
|
+
.tab[aria-disabled='true']:hover,
|
|
394
|
+
.tab[data-disabled='true'],
|
|
395
|
+
.tab[data-disabled='true']:hover {
|
|
355
396
|
color: var(--zdt_v1_tab_text_disabled);
|
|
356
397
|
}
|
|
357
398
|
|
|
358
|
-
.tab[aria-disabled='true'], .tab[aria-disabled='true']:hover {
|
|
399
|
+
.tab[aria-disabled='true'], .tab[aria-disabled='true']:hover, .tab[data-disabled='true'], .tab[data-disabled='true']:hover {
|
|
359
400
|
background-color: transparent;
|
|
360
401
|
}
|
|
@@ -97,6 +97,15 @@ var tabSlots = (0, _cssUtility.csv)({
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
},
|
|
100
|
+
// With `renderAction` the `tab` slot styles a wrapper; the role="tab"
|
|
101
|
+
// trigger inside it is flush, and its ::after stretches over the wrapper
|
|
102
|
+
// so the whole tab stays clickable.
|
|
103
|
+
tabTrigger: {
|
|
104
|
+
base: [_Tab_v1Module["default"].tabTrigger, 'd-min-w-0', 'd-max-w-full', 'd-no-underline', 'd-select-none']
|
|
105
|
+
},
|
|
106
|
+
tabAction: {
|
|
107
|
+
base: [_Tab_v1Module["default"].tabAction, 'd-relative', 'd-inline-flex', 'd-items-center']
|
|
108
|
+
},
|
|
100
109
|
content: {
|
|
101
110
|
// `d-flex` comes from the FlexContainer that renders this slot.
|
|
102
111
|
base: ['d-min-w-0', 'd-max-w-full'],
|
|
@@ -24,6 +24,8 @@ var renderableType = _propTypes["default"].oneOfType([_propTypes["default"].node
|
|
|
24
24
|
var classType = _propTypes["default"].string;
|
|
25
25
|
var tabSlotClasses = {
|
|
26
26
|
tab: classType,
|
|
27
|
+
tabTrigger: classType,
|
|
28
|
+
tabAction: classType,
|
|
27
29
|
content: classType,
|
|
28
30
|
iconBox: classType,
|
|
29
31
|
tabText: classType
|
|
@@ -124,6 +126,10 @@ var tabItemShape = _propTypes["default"].shape({
|
|
|
124
126
|
renderIcon: renderableType,
|
|
125
127
|
renderBefore: renderableType,
|
|
126
128
|
renderAfter: renderableType,
|
|
129
|
+
|
|
130
|
+
/* Rendered beside the tab button, outside it; not shown in the more menu. */
|
|
131
|
+
renderAction: renderableType,
|
|
132
|
+
customClass: _propTypes["default"].shape(tabSlotClasses),
|
|
127
133
|
customId: _propTypes["default"].string,
|
|
128
134
|
testId: _propTypes["default"].string,
|
|
129
135
|
dataSelectorId: _propTypes["default"].string
|
|
@@ -171,6 +177,11 @@ var Tab_propTypes = {
|
|
|
171
177
|
renderIcon: renderableType,
|
|
172
178
|
renderBefore: renderableType,
|
|
173
179
|
renderAfter: renderableType,
|
|
180
|
+
|
|
181
|
+
/* Interactive node rendered beside the role="tab" button, outside it. The
|
|
182
|
+
* `tab` slot then styles a wrapper that also carries customId, testId,
|
|
183
|
+
* dataSelectorId and tourId. */
|
|
184
|
+
renderAction: renderableType,
|
|
174
185
|
onClick: _propTypes["default"].func,
|
|
175
186
|
getRef: _propTypes["default"].oneOfType([_propTypes["default"].func, _propTypes["default"].object]),
|
|
176
187
|
customClass: _propTypes["default"].shape(tabSlotClasses),
|