Skip to content

Combobox + NextJS Link doesn't work with keyboard navigation (Enter) #1821

Answered by RobinMalfait
Strijdhagen asked this question in Help
Discussion options

You must be logged in to vote

It also looks like you are mixing concerns here a bit.

A Menu can be used for actions and links, however a Combobox is used for data, that's why you can select a value from the list.

Instead, I would recommend you to redirect to the correct location based on the value, inside the onChange function. For Next.js that could look like this:

import { useState } from 'react'
import { useRouter } from 'next/router'
import { Combobox } from '@headlessui/react'

const people = [
  'Durward Reynolds',
  'Kenton Towne',
  'Therese Wunsch',
  'Benedict Kessler',
  'Katelyn Rohan',
]

function MyCombobox() {
  const router = useRouter()
  const [selectedPerson, setSelectedPerson] = useState(people[0])
  

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@Strijdhagen
Comment options

@AnnaYuS
Comment options

@mwawrusch
Comment options

Answer selected by Strijdhagen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
4 participants