Site icon Hip-Hop Website Design and Development

Auto focus RichText field

I have a <RichText/> field that I can append more to at the click of a button. But when I click the button and the new RichText field appears, I would like it to be focused so that you can just start typing. At the moment you have to click to add the field and then click again into the field so you can type. Is there a wordpress way to do this or do I need to try and do it using React ref etc…

const addPoint = () => {
    setAttributes({ pricePoints: [...pricePoints, [""]] });
};

<ul>
    {pricePoints.map((p, index) => (
        <li key={index}>
            <RichText
                value={p}
                placeholder="Edit feature"
                onChange={(newValue) =>
                    updatePricePoint(newValue, index)
                }
            />
        </li>
    ))}
    <Button onClick={addPoint} className="append">
        +
    </Button>
</ul>