@herminia_bruen
To set focus to an input in a Storybook story, you can use the useRef hook from React. Here's an example of how you can achieve this:
- Import the useRef hook at the top of your component file:
1
|
import React, { useRef, useEffect } from 'react';
|
- Create a ref for the input element in your component:
1
|
const inputRef = useRef(null);
|
- Use the useEffect hook to set focus to the input element when the component mounts:
1
2
3
|
useEffect(() => {
inputRef.current.focus();
}, []);
|
- Assign the ref to the input element in your JSX:
1
|
<input ref={inputRef} />
|
Now, when the Storybook story containing your component is rendered, the input element should automatically be focused.