Migration Guide for nv-badge
In the latest version of the nv-badge component, we've made several important changes to the properties to improve usability and consistency. Below is a guide to help you update your existing badges from version 2 to version 3.
The component is deprecated
nv-badge is deprecated and will be removed in a future major version. Which component replaces it depends on what the badge was used for:
| Use | Replacement |
|---|---|
| Labelling, categorisation, keywords | nv-tag |
| System-controlled status | nv-statusindicator |
| Interactive, selectable chips (filters, compact toggles) | nv-pill |
Colour mapping: status values
The five status values map onto nv-statusindicator, which keeps the same names and reads from the same --color-feedback-*-low-* tokens as nv-badge, so the colour is unchanged. It also renders a status icon.
| nv-badge | nv-statusindicator |
|---|---|
color="error" | status="error" |
color="information" | status="information" |
color="neutral" | status="neutral" |
color="success" | status="success" |
color="warning" | status="warning" |
nv-statusindicator is static and cannot be dismissed. If you need a dismissible element, use nv-tag and pick a palette colour from the table below.
Colour mapping: palette colours
The named and numeric colours map onto nv-tag. Both components draw from the same rainbow palette, so the colour carries over; nv-tag uses the lighter border token (--color-rainbow-N-border-light), so the outline is slightly softer.
| nv-badge | nv-tag | Palette token |
|---|---|---|
color="1", color="amber" | color="amber" | --color-rainbow-1-* |
color="2", color="orange" | color="orange" | --color-rainbow-2-* |
color="3" | color="yellow" | --color-rainbow-3-* |
color="4" | color="red" | --color-rainbow-4-* |
color="5", color="turquoise" | color="turquoise" | --color-rainbow-5-* |
color="6", color="crimson" | color="crimson" | --color-rainbow-6-* |
color="7" | color="green" | --color-rainbow-7-* |
color="8", color="petrol" | color="blue" | --color-rainbow-8-* |
color="9", color="lime" | color="lime" | --color-rainbow-9-* |
color="10" | color="grey" | --color-rainbow-10-* |
Do not substitute a palette colour for a status value: nv-tag's red is --color-rainbow-4-background (#f9e3e3), while nv-badge's error is --color-feedback-error-low-background (#ffeded). They are close but not the same, and only the status components track the feedback tokens.
Old Usage:
<nv-badge label="Draft" color="10"></nv-badge>
<nv-badge label="Failed" color="error"></nv-badge>
New Usage:
<nv-tag label="Draft" color="grey"></nv-tag>
<nv-statusindicator label="Failed" status="error"></nv-statusindicator>
The sections below remain relevant while you are still on nv-badge.
Deprecations
1. prop dismissal
The dismissal property has been deprecated in favor of dismissible. This change aligns the property name more closely with its function, which is to determine whether the badge can be dismissed.
Old Usage:
<nv-badge dismissal="true"></nv-badge>
New Usage:
<nv-badge dismissible="true"></nv-badge>
2. prop icon
The icon property has been deprecated in favor of leadIcon. This change clarifies that this icon appears at the leading edge of the badge.
Old Usage:
<nv-badge icon="user"></nv-badge>
New Usage:
<nv-badge leadIcon="user"></nv-badge>
3. prop iconLocation
The iconLocation property has been deprecated. The badge now only supports a leading icon.
Old Usage:
<nv-badge icon="user" iconLocation="left"></nv-badge>
New Usage:
<nv-badge leadIcon="user"></nv-badge>
Breaking Changes
1. event close -> closeClicked
The close event has been renamed to closeClicked. This is more descriptive of the event's purpose, as the hiding of the badge could be intercepted by the preventAutoClose prop.
Old Usage:
<nv-badge @close="handleClose"></nv-badge>
New Usage:
<nv-badge @closeClicked="handleClose"></nv-badge>
New Properties
1. hidden Property and hiddenChanged Event
:warning: The new hidden property controls the visibility of the badge and supports animations. The hiddenChanged event emits when the hidden property changes.
Old Code:
<nv-badge
label="User Badge"
dismissal="true"
onClose="handleCloseEvent">
</nv-badge>
New Code:
<nv-badge
label="User Badge"
dismissible="true"
hidden="true"
onHiddenChanged="handleVisibilityChange">
</nv-badge>
2. 'preventAutoClose': Provides a prop to prevent the badge from hiding automatically when the close button is clicked. This is useful for externally controlled component behavior.
New Usage:
<nv-alert dismissible prevent-auto-close></nv-alert>