0.1.4 • Published 5 years ago

a11y-hooks v0.1.4

Weekly downloads
36
License
MIT
Repository
github
Last release
5 years ago

npm.io npm.io

React a11y hooks 🎣♿

A set of hooks to make it easy for everyone to make their site more accessible and improve their ux.

table of contents:

useFocus

  • Programmatically focuses bound element on mount or whenever shouldFocus is set to true.
  • check here for example usage.
const bind = useFocus(arguments?: {
  shouldFocus?: boolean;
  ref?: React.RefObject<HTMLElement>;
})

  ...
   <input {...bind} />

Arguments

NameTypeRequiredDescription
shouldFocusbooleanfalseif provided the bound element will be focused whenever it switches to true
refReact.MutableRefObjectfalseif provided it will focus on the given ref instead of returning bind

useDetectKeyboard

useDetectKeyboard(className?: string)

  • Adds class .user-is-tabbing to document body if user is using tab, this way things like focus styles can be hidden only when the user is navigating via keyboard.
  • check here for example usage.
// in your app.js
function App() {
  useDetectKeyboard();
}
  • also returns a boolean
// with styled components
 function App() {
  const usesTab: boolean = useDetectKeyboard();

  return (
    <GlobalStyles usesTab={usesTab}>
  )

Arguments

NameTypeRequiredDescription
classNamestringfalseif specified adds the provided className to the body instead of .user-is-tabbing
0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago