Skip to content

Commit 2d06b51

Browse files
Remove Action States stories page and move to main stories page.
-Fix tooltip functionality
1 parent 27cf99a commit 2d06b51

2 files changed

Lines changed: 44 additions & 37 deletions

File tree

packages/lib/src/chip/Chip.stories.tsx

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import ExampleContainer from "../../.storybook/components/ExampleContainer";
33
import DxcChip from "./Chip";
44
import { Meta, StoryObj } from "@storybook/react-vite";
55
import { useEffect } from "react";
6+
import { userEvent, within } from "storybook/internal/test";
67

78
export default {
89
title: "Chip",
@@ -133,6 +134,32 @@ const Chip = () => (
133134
/>
134135
</ExampleContainer>
135136

137+
<Title title="Default" theme="light" level={4} />
138+
<ExampleContainer>
139+
<DxcChip label="Default" action={{ icon: "filled_delete", onClick: () => {} }} prefix={{ color: "primary" }} />
140+
</ExampleContainer>
141+
<Title title="Hover" theme="light" level={4} />
142+
<ExampleContainer pseudoState="pseudo-hover">
143+
<DxcChip label="Hover" action={{ icon: "filled_delete", onClick: () => {} }} prefix={{ color: "primary" }} />
144+
</ExampleContainer>
145+
<Title title="Focus" theme="light" level={4} />
146+
<ExampleContainer pseudoState={["pseudo-focus", "pseudo-focus-within"]}>
147+
<DxcChip label="Focus" action={{ icon: "filled_delete", onClick: () => {} }} prefix={{ color: "primary" }} />
148+
</ExampleContainer>
149+
<Title title="Active" theme="light" level={4} />
150+
<ExampleContainer pseudoState="pseudo-active">
151+
<DxcChip label="Active" action={{ icon: "filled_delete", onClick: () => {} }} prefix={{ color: "primary" }} />
152+
</ExampleContainer>
153+
<Title title="Disabled" theme="light" level={4} />
154+
<ExampleContainer>
155+
<DxcChip
156+
label="Disabled"
157+
action={{ icon: "filled_delete", onClick: () => {} }}
158+
prefix={{ color: "primary" }}
159+
disabled
160+
/>
161+
</ExampleContainer>
162+
136163
<Title title="Margins" theme="light" level={2} />
137164
<Title title="Xxsmall margin" theme="light" level={4} />
138165
<ExampleContainer>
@@ -164,37 +191,6 @@ const Chip = () => (
164191
</ExampleContainer>
165192
</>
166193
);
167-
168-
const ChipActionStates = () => (
169-
<>
170-
<Title title="Default" theme="light" level={4} />
171-
<ExampleContainer>
172-
<DxcChip label="Default" action={{ icon: "filled_delete", onClick: () => {} }} prefix={{ color: "primary" }} />
173-
</ExampleContainer>
174-
<Title title="Hover" theme="light" level={4} />
175-
<ExampleContainer pseudoState="pseudo-hover">
176-
<DxcChip label="Hover" action={{ icon: "filled_delete", onClick: () => {} }} prefix={{ color: "primary" }} />
177-
</ExampleContainer>
178-
<Title title="Focus" theme="light" level={4} />
179-
<ExampleContainer pseudoState={["pseudo-focus", "pseudo-focus-within"]}>
180-
<DxcChip label="Focus" action={{ icon: "filled_delete", onClick: () => {} }} prefix={{ color: "primary" }} />
181-
</ExampleContainer>
182-
<Title title="Active" theme="light" level={4} />
183-
<ExampleContainer pseudoState="pseudo-active">
184-
<DxcChip label="Active" action={{ icon: "filled_delete", onClick: () => {} }} prefix={{ color: "primary" }} />
185-
</ExampleContainer>
186-
<Title title="Disabled" theme="light" level={4} />
187-
<ExampleContainer>
188-
<DxcChip
189-
label="Disabled"
190-
action={{ icon: "filled_delete", onClick: () => {} }}
191-
prefix={{ color: "primary" }}
192-
disabled
193-
/>
194-
</ExampleContainer>
195-
</>
196-
);
197-
198194
const ChipTooltip = () => (
199195
<>
200196
<Title title="Chip with Tooltip" theme="light" level={4} />
@@ -214,10 +210,11 @@ export const Chromatic: Story = {
214210
render: Chip,
215211
};
216212

217-
export const ActionStates: Story = {
218-
render: ChipActionStates,
219-
};
220-
221213
export const Tooltip: Story = {
222214
render: ChipTooltip,
215+
play: async ({ canvasElement }) => {
216+
const canvas = within(canvasElement);
217+
const button = await canvas.findByText("Default with tooltip");
218+
await userEvent.hover(button);
219+
},
223220
};

packages/lib/src/chip/Chip.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,18 @@ const DxcChip = ({ action, disabled = false, label, margin, prefix, size = "medi
6464

6565
useLayoutEffect(() => {
6666
if (labelRef.current && label) {
67-
const isOverflowing = labelRef.current.scrollWidth > labelRef.current.clientWidth;
68-
setShowTooltip(isOverflowing);
67+
const element = labelRef.current;
68+
const availableWidth = element.clientWidth;
69+
70+
element.style.overflow = "visible";
71+
element.style.textOverflow = "initial";
72+
73+
const actualWidth = element.scrollWidth;
74+
75+
element.style.overflow = "hidden";
76+
element.style.textOverflow = "ellipsis";
77+
78+
setShowTooltip(actualWidth > availableWidth);
6979
}
7080
}, [label]);
7181

0 commit comments

Comments
 (0)