Skip to content

Commit 1654bb3

Browse files
CopilotCopilot
andcommitted
fix: display resolved value of 0 in token tooltip
The AliasBadge component used `value || ''` which treated 0 as falsy, causing the tooltip to show an empty string instead of '0'. Changed to `value ?? ''` to only fall back for null/undefined. Fixes #3776 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 7d28121 commit 1654bb3

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tokens-studio/figma-plugin": patch
3+
---
4+
5+
Fix token tooltip not displaying resolved value when value is 0

packages/tokens-studio-for-figma/src/app/components/TokenTooltip/AliasBadge.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default function AliasBadge({ value }: Props) {
2121

2222
return (
2323
<StyledAliasBadge>
24-
{formatTokenValueForDisplay(value || '', currentBaseFontSize)}
24+
{formatTokenValueForDisplay(value ?? '', currentBaseFontSize)}
2525
</StyledAliasBadge>
2626
);
2727
}

packages/tokens-studio-for-figma/src/app/components/TokenTooltip/TokenTooltipContent.test.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,20 @@ const tokens: SingleToken[] = [
216216
description: 'a broken reference',
217217
failedToResolve: true,
218218
},
219+
{
220+
name: 'spacing.none',
221+
type: TokenTypes.SPACING,
222+
value: 0,
223+
rawValue: 0,
224+
description: 'zero value token',
225+
},
226+
{
227+
name: 'spacing.alias',
228+
type: TokenTypes.SPACING,
229+
value: 0,
230+
rawValue: '{spacing.none}',
231+
description: 'alias to zero value token',
232+
},
219233
{
220234
name: 'border.regular',
221235
type: TokenTypes.BORDER,
@@ -420,4 +434,22 @@ describe('TokenTooltip alias', () => {
420434
expect(getByText(String('brokentoken'))).toBeInTheDocument();
421435
expect(getByTestId('not-found-badge')).toBeInTheDocument();
422436
});
437+
438+
it('displays resolved value of 0 correctly', () => {
439+
const { getByText } = render(
440+
<TokensContext.Provider value={customStore}>
441+
<TokenTooltipContent
442+
token={{
443+
name: 'spacing.alias',
444+
type: TokenTypes.SPACING,
445+
value: '{spacing.none}',
446+
rawValue: '{spacing.none}',
447+
description: 'alias to zero value token',
448+
}}
449+
/>
450+
</TokensContext.Provider>,
451+
);
452+
453+
expect(getByText('0')).toBeInTheDocument();
454+
});
423455
});

0 commit comments

Comments
 (0)