monday-ui-react-core
Version:
Official monday.com UI resources for application development in React.js
125 lines (114 loc) • 3.2 kB
text/mdx
import { Canvas, Meta } from "@storybook/blocks";
import { FunctionArgument, FunctionArguments, UsageGuidelines } from "vibe-storybook-components";
import * as UseKeyEventStories from "./useKeyEvent.stories";
<Meta of={UseKeyEventStories} />
# useKeyEvent
- [Overview](#overview)
- [Arguments](#arguments)
- [Usage](#usage)
- [Use cases and examples](#use-cases-and-examples)
- [Feedback](#feedback)
## Overview
Attaches a listener to keyboard DOM events on a specific element, firing a provided callback when the event is triggered.
<Canvas of={UseKeyEventStories.Overview} />
## Arguments
<FunctionArguments>
<FunctionArgument name="options" type="Object">
<FunctionArgument
name="keys"
type="Array<string>"
description={
<>
A list of keys to trigger the passed callback. See
<Link href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values">a full list</Link>
for more info.
</>
}
/>
<FunctionArgument
name="callback"
type="(event: Event) => void"
description="Callback function to execute when the event is fired."
required
/>
<FunctionArgument
name="ref"
type="React.MutableRefObject"
description={
<>
A React
<Link href="https://react.dev/reference/react/useRef">ref</Link>
object.
</>
}
default="document"
/>
<FunctionArgument
name="ignoreDocumentFallback"
type="boolean"
description={
<>
If <code>ref</code> is not passed, ignore the default <code>ref</code>.
</>
}
default="false"
/>
<FunctionArgument
name="capture"
type="boolean"
description="Whether to capture the event before bubbling up or not."
default="false"
/>
<FunctionArgument
name="preventDefault"
type="boolean"
description={
<>
Runs{" "}
<code>
<Link href="https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault" withoutSpacing>
preventDefault
</Link>
</code>{" "}
on the fired events.
</>
}
default="false"
/>
<FunctionArgument
name="stopPropagation"
type="boolean"
description={
<>
Runs{" "}
<code>
<Link href="https://developer.mozilla.org/en-US/docs/Web/API/Event/stopPropagation" withoutSpacing>
stopPropagation
</Link>
</code>{" "}
on the fired events.
</>
}
default="false"
/>
<FunctionArgument
name="eventName"
type="string"
description={
<>
The event to listen to. See
<Link href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#events">a full list</Link>
for more info.
</>
}
default="keydown"
/>
</FunctionArgument>
</FunctionArguments>
## Usage
<UsageGuidelines
guidelines={[
"Use this hook to add custom logic when typing inside an element.",
"Use this hook to add keyboard shortcuts."
]}
/>