Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Select's keyboard navigation doesn't work in some cases with v-bind="$attrs" #1585

Closed
zumm opened this issue Jan 28, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@zumm
Copy link
Contributor

zumm commented Jan 28, 2025

Environment

See in reproduction.

Link to minimal reproduction

https://stackblitz.com/edit/vitejs-vite-rsznxfyd?file=src%2FApp.vue

Steps to reproduce

Try to use keyboard navigation in reproduction.

Describe the bug

Lets say we have XSelectItem component like that:

<template>
  <SelectItem as-child>
    <SelectItemText as-child>
      <slot />
    </SelectItemText>
  </SelectItem>
</template>

And XListItem like that:

<script setup lang="ts">
defineOptions({ inheritAttrs: false });
</script>

<template>
  <li>
    <div v-bind="$attrs">
      <slot />
    </div>
  </li>
</template>

If we combine them together:

<template>
  <XSelect>
    <XSelectItem value="1">
      <XListItem>One</XListItem>
    </XSelectItem>

    <XSelectItem value="2">
      <XListItem>Two</XListItem>
    </XSelectItem>
  </XSelect>
</template>

Keyboard navigation will not work. But if we move v-bind="$attrs" from div to li in XListItem navigation will work.

Expected behavior

Keyboard navigation should work regardless of v-bind="$attrs" target, no?

Context & Screenshots (if applicable)

No response

@zumm zumm added the bug Something isn't working label Jan 28, 2025
@zernonia
Copy link
Member

Hi @zumm , thanks for reporting the bug. The reason it's "broken" because we leverage ref to handle certain part of the logic. When you bind attrs to another child (as ref is not being pass onto this child), this breaks the reference element and thus it's not working.

This will not be fixed as it is Vue's current limitation vuejs/rfcs#258

As a simple solution, I would suggest to make following changes:

<template>
  <!-- Render as li element -->
  <SelectItem as="li">
    <SelectItemText as-child>
      <slot />
    </SelectItemText>
  </SelectItem>
</template>
<template> 
  <!-- Need not to bind it manually -->
  <div>
    <slot />
  </div> 
</template>

@zernonia zernonia closed this as not planned Won't fix, can't repro, duplicate, stale Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants