-
Notifications
You must be signed in to change notification settings - Fork 26
Extra keys UI #10
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
Extra keys UI #10
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,40 @@ | ||
| import React from 'react'; | ||
| import React from "react"; | ||
|
|
||
| interface ExtraKeysProps { | ||
| sendKey: (key: string) => void; | ||
| onInputFocus: () => void; | ||
| sendKey: (key: string) => void; | ||
| onInputFocus: () => void; | ||
| } | ||
|
|
||
| const KEYS = ['Esc', 'Tab', 'Ctrl', 'Alt', 'Shift', 'Meta', 'Home', 'End', 'PgUp', 'PgDn', 'Del']; | ||
| const ROWS = [ | ||
| ["Esc", "Tab", "Backspace", "Delete"], | ||
| ["Ctrl", "Alt", "Shift", "Meta", "Fn"], | ||
| ["↑", "←", "↓", "→"], | ||
| ["Play", "Prev", "Next", "Vol-", "Vol+"], | ||
| ]; | ||
|
|
||
| export const ExtraKeys: React.FC<ExtraKeysProps> = ({ sendKey, onInputFocus }) => { | ||
| const handleInteract = (e: React.PointerEvent, key: string) => { | ||
| e.preventDefault(); | ||
| sendKey(key.toLowerCase()); | ||
| onInputFocus(); | ||
| }; | ||
| const press = (e: React.PointerEvent, k: string) => { | ||
| e.preventDefault(); | ||
| sendKey(k.toLowerCase()); | ||
| onInputFocus(); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="bg-base-300 p-2 overflow-x-auto whitespace-nowrap shrink-0 flex gap-2 hide-scrollbar"> | ||
| {KEYS.map(k => ( | ||
| <button | ||
| key={k} | ||
| className="btn btn-sm btn-neutral min-w-[3rem]" | ||
| onPointerDown={(e) => handleInteract(e, k)} | ||
| > | ||
| {k} | ||
| </button> | ||
| ))} | ||
| return ( | ||
| <div className="bg-base-300 p-2 flex flex-col gap-2 shrink-0"> | ||
| {ROWS.map((row, i) => ( | ||
| <div key={i} className="flex gap-2 justify-center"> | ||
| {row.map(k => ( | ||
| <button | ||
| key={k} | ||
| className="btn btn-sm btn-neutral min-w-14 | ||
| " | ||
| onPointerDown={e => press(e, k)} | ||
| > | ||
| {k} | ||
|
Comment on lines
+27
to
+33
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add explicit button type to avoid accidental form submits. ✅ Suggested fix <button
key={k}
+ type="button"
className="btn btn-sm btn-neutral min-w-14
"
onPointerDown={e => press(e, k)}
>🧰 Tools🪛 Biome (2.3.13)[error] 27-33: Provide an explicit type prop for the button element. The default type of a button is submit, which causes the submission of a form when placed inside a (lint/a11y/useButtonType) 🤖 Prompt for AI Agents |
||
| </button> | ||
| ))} | ||
| </div> | ||
| ); | ||
| ))} | ||
| </div> | ||
| ); | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a stable key for rows (avoid array index).
Line 25 uses the array index as a key, which can cause state glitches if rows ever reorder.
✅ Suggested fix
📝 Committable suggestion
🧰 Tools
🪛 Biome (2.3.13)
[error] 25-25: Avoid using the index of an array as key property in an element.
This is the source of the key value.
The order of the items may change, and this also affects performances and component state.
Check the React documentation.
(lint/suspicious/noArrayIndexKey)
🤖 Prompt for AI Agents