Skip to content

Commit e2c94a7

Browse files
committed
feat(tabs): add tab label truncate on constrained width
1 parent ee697bf commit e2c94a7

File tree

4 files changed

+16
-32
lines changed

4 files changed

+16
-32
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- `Tabs`: add tab label truncate on constrained width.
13+
1014
## [3.9.6][] - 2024-12-04
1115

1216
### Added

packages/lumx-core/src/scss/components/tabs/_index.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
========================================================================== */
5353

5454
.#{$lumx-base-prefix}-tabs--layout-fixed {
55+
flex-grow: 1;
56+
5557
.#{$lumx-base-prefix}-tabs__link {
5658
@include lumx-tabs-link-layout("fixed");
5759
}

packages/lumx-react/src/components/tabs/Tab.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { Icon, IconProps, Size } from '@lumx/react';
1+
import React, { FocusEventHandler, forwardRef, KeyboardEventHandler, ReactNode, useCallback } from 'react';
2+
3+
import classNames from 'classnames';
4+
5+
import { Icon, IconProps, Size, Text } from '@lumx/react';
26
import { CSS_PREFIX } from '@lumx/react/constants';
37
import { Comp, GenericProps } from '@lumx/react/utils/type';
48
import { handleBasicClasses } from '@lumx/react/utils/className';
59

6-
import classNames from 'classnames';
7-
import React, { FocusEventHandler, forwardRef, KeyboardEventHandler, ReactNode, useCallback } from 'react';
810
import { useTabProviderContext } from './state';
911

1012
/**
@@ -114,7 +116,11 @@ export const Tab: Comp<TabProps, HTMLButtonElement> = forwardRef((props, ref) =>
114116
aria-controls={state?.tabPanelId}
115117
>
116118
{icon && <Icon icon={icon} size={Size.xs} {...iconProps} />}
117-
{label && <span>{label}</span>}
119+
{label && (
120+
<Text as="span" truncate>
121+
{label}
122+
</Text>
123+
)}
118124
</button>
119125
);
120126
});

packages/lumx-react/src/components/tabs/Tabs.stories.tsx

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -52,34 +52,6 @@ export const Controlled = ({ theme }: any) => {
5252
);
5353
};
5454

55-
/* Control active tab internally (with activate tab on focus). */
56-
export const NotControlled = ({ theme }: any) => {
57-
return (
58-
<TabProvider shouldActivateOnFocus onChange={console.log}>
59-
<TabList theme={theme} aria-label="Tab list">
60-
<Tab label="Tab a" />
61-
<Tab label="Tab b" />
62-
</TabList>
63-
<TabPanel className="lumx-spacing-padding-huge">Tab a content</TabPanel>
64-
<TabPanel className="lumx-spacing-padding-huge">Tab b content</TabPanel>
65-
</TabProvider>
66-
);
67-
};
68-
69-
/* Display tabs far from their tab panels. */
70-
export const DisabledTab = ({ theme }: any) => (
71-
<TabProvider shouldActivateOnFocus>
72-
<TabList theme={theme} aria-label="Tab list">
73-
<Tab label="Tab 1" />
74-
<Tab label="Tab 2" isDisabled />
75-
<Tab label="Tab 3" />
76-
</TabList>
77-
<TabPanel className="lumx-spacing-padding-huge">Tab 1 content</TabPanel>
78-
<TabPanel className="lumx-spacing-padding-huge">Tab 2 content</TabPanel>
79-
<TabPanel className="lumx-spacing-padding-huge">Tab 3 content</TabPanel>
80-
</TabProvider>
81-
);
82-
8355
/* Display tabs far from their tab panels. */
8456
export const SplitTabListAndTabPanels = ({ theme }: any) => {
8557
const [isOpen, setOpen] = useState(true);

0 commit comments

Comments
 (0)