mirror of
https://github.com/coder/coder.git
synced 2026-11-16 20:50:12 +08:00
22 lines
423 B
TypeScript
22 lines
423 B
TypeScript
import { KeyboardEvent } from "react"
|
|
|
|
interface UseClickableResult {
|
|
tabIndex: 0
|
|
role: "button"
|
|
onClick: () => void
|
|
onKeyDown: (event: KeyboardEvent) => void
|
|
}
|
|
|
|
export const useClickable = (onClick: () => void): UseClickableResult => {
|
|
return {
|
|
tabIndex: 0,
|
|
role: "button",
|
|
onClick,
|
|
onKeyDown: (event: KeyboardEvent) => {
|
|
if (event.key === "Enter") {
|
|
onClick()
|
|
}
|
|
},
|
|
}
|
|
}
|