Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

keyboard nav for list items

Terry Suttone3f2c6794ea8
diff --git a/packages/ui/src/components/Command/GenerateSQL/GenerateSQL.tsx b/packages/ui/src/components/Command/GenerateSQL/GenerateSQL.tsx
index bd018484210..0f50c348df9 100644
--- a/packages/ui/src/components/Command/GenerateSQL/GenerateSQL.tsx
+++ b/packages/ui/src/components/Command/GenerateSQL/GenerateSQL.tsx
@@ -1,3 +1,4 @@
+import React from 'react'
import { format } from 'sql-formatter'
import { useCallback, useEffect, useRef, useState } from 'react'
import {
@@ -79,6 +80,15 @@ const GenerateSQL = () => {
}
}
+ const handleKeypress = (e, category) => {
+ //it triggers by pressing the enter key
+ if (e.keyCode === 13) {
+ setSelectedCategory(category)
+ // focus on the first item in the list after selecting a category
+ const firstItem = document.querySelector('.command-menu-item')
+ }
+ }
+
return (
<div onClick={(e) => e.stopPropagation()}>
<div
@@ -177,15 +187,18 @@ const GenerateSQL = () => {
<div className="w-1/3 py-4 px-6">
<ul className="space-y-2">
{SAMPLE_QUERIES.map((item, index) => (
- <li
- key={index}
- onClick={() => setSelectedCategory(item.category)}
- className={cn(
- 'px-4 py-1 cursor-pointer text-sm hover:bg-slate-300 rounded-md',
- selectedCategory === item.category && 'bg-slate-400 '
- )}
- >
- {item.category}
+ <li key={index}>
+ <button
+ className={cn(
+ 'px-4 py-1 cursor-pointer text-sm hover:bg-slate-300 rounded-md block w-full text-left',
+ selectedCategory === item.category && 'bg-slate-400 '
+ )}
+ type="button"
+ onClick={() => setSelectedCategory(item.category)}
+ onKeyDown={(e) => handleKeypress(e, item.category)}
+ >
+ {item.category}
+ </button>
</li>
))}
</ul>
@@ -194,23 +207,41 @@ const GenerateSQL = () => {
<ul>
{SAMPLE_QUERIES.find((item) => item.category === selectedCategory)?.queries.map(
(query, index) => (
- <CommandItem
- type="command"
- onSelect={() => {
+ <button
+ onClick={() => {
if (!search) {
handleSubmit(query)
}
}}
- forceMount
key={query.replace(/\s+/g, '_')}
+ type="button"
>
<div className="flex">
<div>
<AiIcon />
</div>
- <p>{query}</p>
+ {query}
</div>
- </CommandItem>
+ </button>
+ // <CommandItem
+ // type="command"
+ // onSelect={() => {
+ // if (!search) {
+ // handleSubmit(query)
+ // }
+ // }}
+ // forceMount
+ // key={query.replace(/\s+/g, '_')}
+ // >
+ // <div className="flex">
+ // <div>
+ // <AiIcon />
+ // </div>
+ // <p>
+ // <button type="button">{query}</button>
+ // </p>
+ // </div>
+ // </CommandItem>
)
)}
</ul>