Last modified: 4/Oct/2024
useKeyboardFocus
By default, you cannot decide about a focus event, that it happened via keyboard or mouse. This hook use a workaround to do that, so you can apply different styles.
#Usage
import { useKeyboardFocus } from '@kinsta/stratus'
const MyComponent = ({ focusStyle, keyboardFocusStyle }) => {
const { ref, isInFocus, isInFocusKeyboard } = useKeyboardFocus<HTMLButtonElement>()
const style = isInFocusKeyboard
? keyboardFocusStyle
: isInFocus
? focusStyle
: {}
return (
<button ref={ref} style={style}>Focus button</button>
)
}
#Parameters
#isDisabled
boolean
#isReadOnly
boolean
select
method runs instead of focus
) - Defaults to false#Types
-
UseKeyboardFocus
Read more about types here