[//]: # (This file is auto-generated by the docs:generate-skills script, do not edit it manually)

# OperationalTag

Import: `import { OperationalTag } from '@neo4j-ndl/react'`

## Props

### OperationalTag

| Prop | Type | Required | Default | Description |
|------|------|----------|---------|-------------|
| `children` | `ReactNode` |  |  | The content of the tag |
| `isActive` | `boolean` |  |  | Whether the tag is in an active (pressed) state |
| `isDisabled` | `boolean` |  | `false` | Whether the tag is disabled |
| `leadingColor` | `Color` |  |  | Decorative color shown before the content to help users recognize the item. It carries no meaning of its own and is hidden from assistive technology, so the tag text must identify the item. Accepts a CSS variable or a hex color. |
| `leadingVisual` | `ReactNode` |  |  | Icon to display before the content |
| `onClick` | `MouseEventHandler<HTMLButtonElement>` |  |  | Callback fired when the tag is clicked |
| `ref` | `Ref<HTMLButtonElement>` |  |  | A ref to apply to the root element. |
| `size` | `'large' \| 'medium' \| 'small' \| 'x-small'` |  | `medium` | Size of the tag |

Clickable tag for actions and for identifying an item with a color or icon.
For choosing from a set of options, use `SelectableTag`.

## Accessibility

## Keyboard interactions

The tag renders as a native `<button>` so it uses standard button keyboard behavior.

| Key           | Description                                     |
| ------------- | ----------------------------------------------- |
| `Tab`         | Moves focus to the tag                          |
| `Shift + Tab` | Moves focus to the previous focusable element   |
| `Enter`       | Activates the tag (calls `onClick` if provided) |
| `Space`       | Activates the tag (calls `onClick` if provided) |

A disabled tag (`isDisabled`) uses the native `disabled` attribute. It is removed from the tab order and cannot be activated.

## WAI-ARIA roles and attributes

- The root is a `<button type="button">` which gives it the `button` role and an accessible name from its text content.
- `aria-pressed` is only set when `isActive` is explicitly provided: `true` when active, `false` when `isActive={false}`. It is omitted when `isActive` is not passed, so a plain action tag is not announced as a toggle button.
- The leading color dot is decorative and has `aria-hidden="true"`. It is not announced by screen readers.
- The leading visual is not given a label by the component. Provide meaning through the tag text, or make sure the icon is decorative.

## Implementation guidelines

- `leadingColor` is a recognition aid, not a way to convey information. Use it for things like a color a user has picked for a database or instance. The tag text must always identify the item, because the color is hidden from assistive technology and can't be perceived by everyone, including people with color vision deficiency. Do not use it to show status, category, or any other meaning.
- Choose custom colors with enough contrast against the tag background in both themes. A color close to the background (for example white on white) can make the dot invisible. Prefer a design token (for example `var(--categorical-1)`), which is defined for each theme.
- Only pass `isActive` when the tag represents a toggled state (a selected filter). Otherwise leave it out so it is not announced as pressed or not pressed.
- Text that is truncated is cut with an ellipsis. Make sure the full text is available elsewhere (for example in a tooltip) when it carries meaning (see the Truncation story).

### Related WCAG criteria

- [1.4.1 Use of Color](https://www.w3.org/WAI/WCAG22/Understanding/use-of-color.html) (A): The leading color must not be the only means of conveying information.
- [1.4.11 Non-text Contrast](https://www.w3.org/WAI/WCAG22/Understanding/non-text-contrast.html) (AA): Custom leading colors need sufficient contrast against the tag background.
- [2.1.1 Keyboard](https://www.w3.org/WAI/WCAG22/Understanding/keyboard.html) (A): The tag is a native button and fully keyboard operable.
- [4.1.2 Name, Role, Value](https://www.w3.org/WAI/WCAG22/Understanding/name-role-value.html) (A): The role comes from the native `<button>`, the name from the text content, and `aria-pressed` conveys the active state.

## Examples

### Default

```tsx
import '@neo4j-ndl/base/lib/neo4j-ds-styles.css';

import { OperationalTag } from '@neo4j-ndl/react';

const Component = () => {
  return <OperationalTag>Operational Tag</OperationalTag>;
};

export default Component;
```

### Active

```tsx
import '@neo4j-ndl/base/lib/neo4j-ds-styles.css';

import { OperationalTag } from '@neo4j-ndl/react';

const Component = () => {
  return <OperationalTag isActive>Active operational tag</OperationalTag>;
};

export default Component;
```

### Disabled

```tsx
import '@neo4j-ndl/base/lib/neo4j-ds-styles.css';

import { OperationalTag } from '@neo4j-ndl/react';

const Component = () => {
  return <OperationalTag isDisabled>Disabled operational tag</OperationalTag>;
};

export default Component;
```

### Sizes

```tsx
import '@neo4j-ndl/base/lib/neo4j-ds-styles.css';

import { OperationalTag } from '@neo4j-ndl/react';

const Component = () => {
  return (
    <div className="flex flex-row gap-token-8">
      <OperationalTag size="x-small">X-Small</OperationalTag>
      <OperationalTag size="small">Small</OperationalTag>
      <OperationalTag size="medium">Medium</OperationalTag>
      <OperationalTag size="large">Large</OperationalTag>
    </div>
  );
};

export default Component;
```

### Truncation

```tsx
import '@neo4j-ndl/base/lib/neo4j-ds-styles.css';

import { OperationalTag, Tooltip } from '@neo4j-ndl/react';

const label =
  'This is a very very very long tag label that should be truncated';

const Component = () => {
  return (
    <div style={{ maxWidth: 200 }}>
      <Tooltip type="simple">
        <Tooltip.Trigger hasButtonWrapper>
          <OperationalTag>{label}</OperationalTag>
        </Tooltip.Trigger>
        <Tooltip.Content>{label}</Tooltip.Content>
      </Tooltip>
    </div>
  );
};

export default Component;
```

### With Leading Color

```tsx
import '@neo4j-ndl/base/lib/neo4j-ds-styles.css';

import { OperationalTag } from '@neo4j-ndl/react';

const Component = () => {
  return (
    <OperationalTag leadingColor="var(--categorical-1)">
      Operational Tag with leading color
    </OperationalTag>
  );
};

export default Component;
```

### With Leading Icon

```tsx
import '@neo4j-ndl/base/lib/neo4j-ds-styles.css';

import { OperationalTag } from '@neo4j-ndl/react';
import { DatabasePlusIcon } from '@neo4j-ndl/react/icons';

const Component = () => {
  return (
    <OperationalTag leadingVisual={<DatabasePlusIcon />}>
      Operational Tag with leading icon
    </OperationalTag>
  );
};

export default Component;
```
