Skip to content

fix(TagsInput): keep disabled tags out of keyboard removal index - #2786

Merged
zernonia merged 1 commit into
unovue:v2from
JoMarchant:fix/tags-input-disabled-remove-index
Jul 23, 2026
Merged

zernonia merged 1 commit into
unovue:v2from
JoMarchant:fix/tags-input-disabled-remove-index

Conversation

@JoMarchant

@JoMarchant JoMarchant commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2785

Description

TagsInput removed the wrong tag on keyboard delete when a disabled TagsInputItem was present.

The keyboard handler computes the selected tag's index against a disabled-filtered collection:

const collection = getItems().map(i => i.ref).filter(i => i.dataset.disabled !== '') // removable-only
const index = collection.findIndex(i => i === selectedElement.value)
handleRemoveTag(index)

…but handleRemoveTag applied that index to the full model:

modelValue.value = modelValue.value.filter((_, i) => i !== index)

Since getItems() already excludes disabled items, the filtered index doesn't match the model index whenever a disabled item exists. Symptoms:

  • A disabled tag placed before removable ones gets deleted instead of the selected tag.
  • With only disabled tags left, Backspace could still remove one.

TagsInputItemDelete was unaffected because it already resolves the model index by value (modelValue.findIndex(isEqual(...))).

Fix

  • Resolve the keyboard-selected tag to its index in modelValue by value (via ohash's isEqual, mirroring TagsInputItemDelete) before removing.
  • Make handleRemoveTag emit the value that was actually removed (modelValue[index]) instead of indexing the disabled-filtered collection — this also fixes an incorrect removeTag payload from the delete button when disabled items are present.

Navigation still uses the disabled-filtered collection, so disabled items remain unreachable/unselectable.

Repro (before this PR)

<script setup lang="ts">
import { ref } from 'vue'
import { TagsInputRoot, TagsInputItem, TagsInputItemText, TagsInputItemDelete, TagsInputInput } from 'reka-ui'
const modelValue = ref(['admin@acme.com', 'user@gmail.com'])
const isDisabled = (v: string) => v === 'admin@acme.com'
</script>

<template>
  <TagsInputRoot v-model="modelValue">
    <TagsInputItem v-for="item in modelValue" :key="item" :value="item" :disabled="isDisabled(item)">
      <TagsInputItemText />
      <TagsInputItemDelete v-if="!isDisabled(item)" />
    </TagsInputItem>
    <TagsInputInput placeholder="Add..." />
  </TagsInputRoot>
</template>

Focus the input → Backspace (selects user@gmail.com) → Backspace again.

  • Before: admin@acme.com (disabled) is removed.
  • After: user@gmail.com is removed. ✅

Tests

Added a colocated test fixture (story/_TagsInputDisabled.vue) and cases in TagsInput.test.ts:

  • keyboard delete removes the selected removable tag (not the disabled one),
  • the disabled tag is never removed when it's the only tag left.

All TagsInput tests pass; type-check and lint are green.

Keyboard delete computed the removal index from the disabled-filtered
collection but `handleRemoveTag` applied it to the full model, so with a
disabled item present the wrong tag was removed — e.g. a disabled tag
placed before removable ones would be deleted instead of the selected
tag, and pressing Backspace with only disabled tags left could still
remove one.

Resolve the selected tag to its index in `modelValue` by value (mirroring
`TagsInputItemDelete`), and make `handleRemoveTag` emit the value that was
actually removed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

TagsInputRoot now resolves keyboard deletion against modelValue indexes, preserving disabled tags during removal. A disabled-tag fixture and regression tests cover repeated Backspace behavior.

Changes

TagsInput disabled removal

Layer / File(s) Summary
Resolve keyboard removal by model index
packages/core/src/TagsInput/TagsInputRoot.vue
Selected tags are matched to modelValue with isEqual; removal and removeTag emission use the resolved model index.
Add disabled-tag regression coverage
packages/core/src/TagsInput/story/_TagsInputDisabled.vue, packages/core/src/TagsInput/TagsInput.test.ts
Adds a disabled/removable tag fixture and tests that Backspace removes only the removable tag, including repeated presses.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

  • unovue/reka-ui#2785 — Directly covers the disabled-tag keyboard deletion index mismatch addressed by this change.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main fix: preventing disabled tags from being targeted by keyboard removal in TagsInput.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@JoMarchant
JoMarchant marked this pull request as draft July 10, 2026 20:43
@JoMarchant
JoMarchant marked this pull request as ready for review July 10, 2026 20:46
@zernonia

Copy link
Copy Markdown
Member

LGTM! Thanks @JoMarchant !

@pkg-pr-new

pkg-pr-new Bot commented Jul 23, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/reka-ui@2786

commit: 5e4b781

@zernonia
zernonia merged commit fc8c127 into unovue:v2 Jul 23, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: TagsInput removes the wrong tag via keyboard when a disabled item is present

2 participants