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

Dropdown tailwind integration: focused item not highlighted #7073

Closed
rootssoftware opened this issue Aug 22, 2024 · 2 comments · Fixed by #7107
Closed

Dropdown tailwind integration: focused item not highlighted #7073

rootssoftware opened this issue Aug 22, 2024 · 2 comments · Fixed by #7107
Assignees
Labels
Component: Tailwind Tailwind specific issue
Milestone

Comments

@rootssoftware
Copy link

rootssoftware commented Aug 22, 2024

Describe the bug

A user can type/use the arrow keys to select a value in the dropdown list.
In the examples on the primereact site (https://primereact.org/dropdown/), the currently focused item ius highlighted with a light gray background.

correct

The tailwind example does not highlight the focused item though (https://stackblitz.com/run?file=src%2FApp.jsx).

incorrect

This despite a properly defined pass through object:

dropdown: {
        ...
  item: ({context}) => ({
    className: classNames(
      'cursor-pointer font-normal overflow-hidden relative whitespace-nowrap',
      'm-0 p-3 border-0  transition-shadow duration-200 rounded-none',
      'dark:text-white/80 dark:hover:bg-gray-800',
      'hover:text-gray-700 hover:bg-gray-200',
      {
        'text-gray-700': !context.focused && !context.selected,
        'bg-gray-300 text-gray-700 dark:text-white/80 dark:bg-gray-800/90': context.focused && !context.selected,
        'bg-blue-400 text-blue-700 dark:bg-blue-400 dark:text-white/80': context.focused && context.selected,
        'bg-[var(--primary-green-light)] text-[var(--primary-green)] dark:bg-blue-300 dark:text-white/80': !context.focused && context.selected,
        'opacity-60 select-none pointer-events-none cursor-default': context.disabled
      }
    )
  }),
        ...
}

Reproducer

https://stackblitz.com/run?file=src%2FApp.jsx

System Information

System:
OS: Linux 6.8 TUXEDO OS 2 22.04.4
CPU: (16) x64 AMD Ryzen 7 5700U with Radeon Graphics
Memory: 5.14 GB / 30.73 GB
Container: Yes
Shell: 5.1.16 - /bin/bash
Binaries:
Node: 22.6.0 - /home/linuxbrew/.linuxbrew/bin/node
npm: 10.8.2 - /home/linuxbrew/.linuxbrew/bin/npm
Browsers:
Chrome: 127.0.6533.119
npmPackages:
primereact: 10.8.0 => 10.8.0
react: 18.3.1 => 18.3.1
tailwindcss: 3.4.7 => 3.4.7

Steps to reproduce the behavior

  1. Select the dropdown
  2. Start typing one of the options/press the down arrow key

Expected behavior

The currently focused item (the one that will be selected after pressing enter) has a light gray background

@rootssoftware rootssoftware added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Aug 22, 2024
@melloware melloware added Component: Tailwind Tailwind specific issue and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Aug 23, 2024
@gcko
Copy link
Contributor

gcko commented Sep 4, 2024

I can see that keyboard interactions are still captured and the data-p-focused attribute on each item does update, however the CSS classes are not updating. The fix will be to ensure the classes update on focus change

gcko added a commit to gcko/primereact that referenced this issue Sep 4, 2024
@gcko
Copy link
Contributor

gcko commented Sep 4, 2024

Screenshot 2024-09-04 at 13 34 06

focused was not correctly added to the context, meaning that even though the styles are correct in the Tailwind doc, they were not being applied.

This is fixed in PR #7107

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Tailwind Tailwind specific issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants