gog-chip
Chip
A compact, clickable label with five sizes, two shapes, and optional avatar, icon, and remove affordances.
Overview
Import the component and drop it into a template.
import { ChipComponent } from '@guildofgleks/ui';
@Component({
// ...
imports: [ChipComponent],
})
Basic usage — clickable chips with projected content, reporting gogClick:
gogClick: nothing yet
<gog-chip (gogClick)="lastClicked.set('Design')">Design</gog-chip>
<gog-chip (gogClick)="lastClicked.set('Research')">Research</gog-chip>
<p>gogClick: {{ lastClicked() }}</p>Examples
Avatar, icon and remove button
The avatar, the icon and the remove button are each a ratio of the chip's own font size, so the whole object scales from one number. avatarUrl and iconName are independent — set both and both render.
@for (size of sizes; track size) {
<div>
<span>size: {{ size }}</span>
<gog-chip [size]="size" [avatarUrl]="ada" avatarAlt="">Ada Lovelace</gog-chip>
<gog-chip [size]="size" iconName="star">Starred</gog-chip>
<!-- Avatar and icon are independent: set both and both render. -->
<gog-chip
[size]="size"
[avatarUrl]="alan"
avatarAlt=""
iconName="warning"
removable
removeAriaLabel="Remove Alan Turing"
>
Alan Turing
</gog-chip>
</div>
}When the picture fails 21.19.0
The avatar is a gog-avatar at the chip's own size, so a URL that fails falls back the way an avatar does: to the initials of avatarAlt, or to the person icon without one — never the browser's broken-image glyph. With no avatarAlt the avatar stays decorative, as alt="" did; with one it is named by it, as before.
<div>
<gog-chip [avatarUrl]="ada" avatarAlt="Ada Lovelace">Ada Lovelace</gog-chip>
<span>picture</span>
</div>
<div>
<!-- An image that cannot load. On this server-rendered page it fails before the app hydrates. -->
<gog-chip [avatarUrl]="broken" avatarAlt="Grace Hopper">Grace Hopper</gog-chip>
<span>fails, with avatarAlt</span>
</div>
<div>
<gog-chip [avatarUrl]="broken">Guest</gog-chip>
<span>fails, no avatarAlt</span>
</div>Shapes
rounded (the default) or a fully rounded pill, with and without an avatar and a remove button.
@for (shape of shapes; track shape) {
<gog-chip [shape]="shape">shape="{{ shape }}"</gog-chip>
<gog-chip [shape]="shape" [avatarUrl]="ada" avatarAlt="" removable>Ada Lovelace</gog-chip>
}Filter chips
[(selected)] turns a row of chips into toggles that need no click handler: each flips its own value on click, Enter and Space, and announces aria-pressed. gogClick still fires, after the flip, so a handler reading the value sees the new one; if the page drives the state itself from that handler, bind one-way — [selected] — or the two flips cancel out. For a choice of exactly one, this is the wrong component: use gog-button-toggle-group or a radio group.
selected: Accessibility, Forms
<!-- Two-way: each chip flips its own value on click, Enter and Space. -->
@for (topic of topics; track topic.label) {
<gog-chip [(selected)]="topic.on">{{ topic.label }}</gog-chip>
}
<p>selected: {{ selectedTopics().join(', ') || 'none' }}</p>Removable
removable adds a button that emits gogRemove; the chip does not remove itself, the list it came from does. The button works from the keyboard removeAriaLabel that says what it removes — the default, "Remove chip", is the same for every chip in the row. These chips are [clickable]="false", since removing is their only action. A disabled chip hides its button rather than offering one that does nothing.
last: nothing yet
<!-- The chip does not remove itself: the list it came from does. -->
@for (filter of filters(); track filter) {
<gog-chip
[clickable]="false"
removable
[removeAriaLabel]="'Remove filter ' + filter"
(gogRemove)="remove(filter)"
>
{{ filter }}
</gog-chip>
}
<gog-chip [clickable]="false" removable disabled>Disabled hides the button</gog-chip>
<gog-button variant="outline" size="sm" (gogClick)="reset()">Reset</gog-button>
<p>last: {{ lastAction() }}</p>Full width
Off by default. On, the chip fills its container — the dashed box here — and the remove button stays at the end.
<gog-chip>fullWidth unset</gog-chip>
<!-- The remove button stays at the end of the stretched chip. -->
<gog-chip fullWidth removable>fullWidth</gog-chip>App-wide defaults — GOG_CONFIG
The ripple is the only key a chip reads: ripple.enabled turns it on for every chip under the provider, and an instance's [ripple] still wins. Press each. A chip that is not clickable never ripples — a label that waves at a press promises something it will not do. In an app the provider goes in app.config.ts — see Global Configuration.
<gog-chip>Ripple from the config</gog-chip>
<gog-chip [ripple]="false">[ripple]="false" — the instance wins</gog-chip>
<!-- A label never ripples, whatever the config says. -->
<gog-chip [clickable]="false">Not clickable</gog-chip>Accessibility
A clickable chip is a role="button" with a tab stop; a filter chip adds aria-pressed; a label chip is plain text.
- Name — the chip's content, or
ariaLabel. A removable chip is two sibling buttons, so the chip is named by its content alone — "Angular", not "Angular Remove filter Angular" — and the remove button byremoveAriaLabel. - Keyboard — Tab reaches the chip and then its remove button; Enter or Space presses whichever has focus.
- State —
aria-pressedwhileselectedistrueorfalse.falseis written, not left out, because a chip with noaria-pressedis not a toggle to a screen reader at all;nullwrites nothing. A disabled chip dropsrole="button"and with itaria-pressed, though it keeps the ring on screen. clickableis on by default, so every chip is a button and a tab stop unless it says otherwise. A chip that only shows a value should set[clickable]="false", or a keyboard user tabs through buttons that do nothing. For a coloured status label, gog-tag is the component.
API Reference
Inputs
| Name | Type | Default | Description |
|---|---|---|---|
size | 'xsm' | 'sm' | 'md' | 'lg' | 'slg' | 'md' | Font size, padding, gap, and avatar/icon size. |
shape | 'rounded' | 'pill' | 'rounded' | Corner radius style. |
disabled | boolean | false | Blocks click/keyboard activation and hides the remove button, regardless of removable. |
clickable | boolean | true | Whether the chip responds to click/Enter/Space and exposes role="button". Set false for a static, non-interactive label. |
selected | boolean | null | null | Two-way. Makes the chip a filter chip: one you toggle rather than press. null is not a toggle at all and is the default, so an existing chip is untouched; false is a toggle that is off and says so with aria-pressed="false"; true is on and draws an inset ring. The chip flips it itself on click, Enter and Space. |
removable | boolean | false | Shows a trailing remove (×) button that emits gogRemove. |
fullWidth | boolean | false | Stretches the chip to fill its container. |
ariaLabel | string | '' | Accessible name for the chip surface. |
removeAriaLabel | string | 'Remove chip' | Accessible name for the remove button. |
avatarUrl | string | null | null | Leading avatar image, drawn by a gog-avatar at the chip’s own size (since 21.19.0). A URL that fails falls back to the initials of avatarAlt, or to the person icon. |
avatarAlt | string | '' | Names the avatar, and gives the initials it falls back to. Empty, the avatar is decorative. |
iconName | GogIconName | null | null | Leading icon. Renders independently of avatarUrl — if both are set, the avatar and icon both render. |
ripple | boolean | undefined | undefined | Press ripple on the chip surface. Unset, falls back to GOG_CONFIG.ripple.enabled, which is off by default; setting it here wins over the app-wide value in both directions. |
Outputs
| Name | Payload | Description |
|---|---|---|
gogClick | MouseEvent | KeyboardEvent | Emitted on click, Enter, or Space, when clickable and not disabled — after the flip, for a filter chip. |
gogRemove | void | Emitted when the remove button is pressed. Stops the click from also reaching gogClick. |
selectedChange | boolean | null | The flipped value of a filter chip. Comes from the selected model input. |
Global Configuration
Set any of these once with provideGogConfig() instead of repeating them on every instance — an instance's own input still wins when it sets one itself. See Global Configuration for the full reference.
GOG_CONFIG.ripple.enabled
This site is not on the default here. The library ships ripple.enabled as false; these docs set it to true app-wide so the demos above actually show the press feedback. In a fresh app you get no ripple until you ask for one — the droplet button in the header switches this site between the two, and it is on right now.
Styling Tokens
Every CSS custom property the chip paints with. Override any of them — on a single instance, a subtree, or a theme — to restyle it. See the Theming guide for the full token-layering model, or the Theme Generator to tweak these live.
| Token | Description |
|---|---|
--gog-chip-bg / -hover-bg / -press-bg | Background, default, hover and pressed. |
--gog-chip-selected-shadow / -selected-ring-width | The inset ring a filter chip draws while selected ([(selected)], 21.9.0). A ring rather than a fill, because hover and press already own the background. |
--gog-chip-border / -border-width / -style | Border. Since 21.12.0 the colour defaults to --gog-control-boundary-color rather than the decorative --gog-border-color: a chip is a control, and its edge is what identifies it. That is why chips look outlined more firmly than they did — they were at 1.18:1 in primeng before. |
--gog-chip-focus-ring-color / -width / -offset | The keyboard focus ring. The colour is new in 21.12.0 — the chip had a width and an offset but no colour of its own, so the stylesheet reached for --gog-chip-border and the ring came out as a hairline. A focus indicator needs its own colour. |
--gog-chip-color / -font-weight | Text color and weight. |
--gog-chip-radius / -pill-radius | Corner radius, square and pill shape. |
--gog-chip-remove-color / -remove-hover-color | Remove (×) icon color. |
--gog-chip-{size}-font-size / -padding-block / -padding-inline / -gap / -avatar-size / -icon-size / -remove-size | Full sizing scale, per size step (xsm/sm/md/lg/slg). The three glyph sizes are ratios of the chip’s own type rather than px ladders since 21.11.0 — avatar 1.5em, icon 1em, remove mark 1.125em, one value at every size — so overriding a size’s font-size carries its glyphs with it, which the rem ladder did not. |