Skip to content

Commit 6d523eb

Browse files
committed
fix(XI-7052): Support text wrapping in vertical TabList
1 parent 542e48d commit 6d523eb

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

packages/@adobe/spectrum-css-temp/components/tabs/index.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,19 @@ governing permissions and limitations under the License.
238238
}
239239
}
240240

241+
/*
242+
Allow tab labels to wrap when TabList component has minWidth set.
243+
*/
244+
&.spectrum-Tabs--verticalWrap:not(.spectrum-Tabs--compact) .spectrum-Tabs-item {
245+
display: flex;
246+
align-items: center;
247+
white-space: normal;
248+
line-height: normal;
249+
word-break: break-word;
250+
block-size: auto;
251+
min-height: var(--spectrum-tabs-vertical-item-height);
252+
}
253+
241254
&.spectrum-Tabs--compact {
242255
.spectrum-Tabs-item {
243256
block-size: var(--spectrum-tabs-compact-vertical-item-height);

packages/@react-spectrum/tabs/src/Tabs.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ function TabLine(props: TabLineProps) {
261261
* A TabList is used within Tabs to group tabs that a user can switch between.
262262
* The keys of the items within the <TabList> must match up with a corresponding item inside the <TabPanels>.
263263
*/
264-
export function TabList<T>(props: SpectrumTabListProps<T>): ReactNode {
264+
export function TabList<T>(props: SpectrumTabListProps<T> & {wrap?: boolean}): ReactNode {
265265
const tabContext = useContext(TabContext)!;
266266
const {refs, tabState, tabProps, tabPanelProps} = tabContext;
267267
const {isQuiet, density, isEmphasized, orientation} = tabProps;
@@ -288,6 +288,8 @@ export function TabList<T>(props: SpectrumTabListProps<T>): ReactNode {
288288

289289
let tabListclassName = classNames(styles, 'spectrum-TabsPanel-tabs');
290290

291+
const verticalWrap = props.wrap && orientation === 'vertical';
292+
291293
const tabContent = (
292294
<div
293295
{...stylePropsFinal}
@@ -301,7 +303,8 @@ export function TabList<T>(props: SpectrumTabListProps<T>): ReactNode {
301303
{
302304
'spectrum-Tabs--quiet': isQuiet,
303305
'spectrum-Tabs--emphasized': isEmphasized,
304-
['spectrum-Tabs--compact']: density === 'compact'
306+
['spectrum-Tabs--compact']: density === 'compact',
307+
'spectrum-Tabs--verticalWrap': verticalWrap
305308
},
306309
orientation === 'vertical' && styleProps.className
307310
)

packages/@react-types/tabs/src/index.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,12 @@ export interface SpectrumTabsProps<T> extends AriaTabListBase, Omit<SingleSelect
7878

7979
export interface SpectrumTabListProps<T> extends DOMProps, StyleProps {
8080
/** The tab items to display. Item keys should match the key of the corresponding `<Item>` within the `<TabPanels>` element. */
81-
children: CollectionChildren<T>
81+
children: CollectionChildren<T>,
82+
/**
83+
* When `true`, tab labels will wrap if they exceed the TabList's width. Only supported in vertical orientation with `regular` density. For proper wrapping, set a `minWidth` on TabList.
84+
* @default false
85+
*/
86+
wrap?: boolean
8287
}
8388

8489
export interface SpectrumTabPanelsProps<T> extends DOMProps, StyleProps {

0 commit comments

Comments
 (0)