From c39ce54014592ab866d7fed31b431ff1c96bc836 Mon Sep 17 00:00:00 2001 From: Lukas Lohoff Date: Mon, 18 Nov 2024 11:53:33 +0100 Subject: [PATCH 1/2] fix: enable drawbutton autofocus on text area --- src/FeatureLabelModal/FeatureLabelModal.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/FeatureLabelModal/FeatureLabelModal.tsx b/src/FeatureLabelModal/FeatureLabelModal.tsx index 2f68c8314a..af9ff89ec8 100644 --- a/src/FeatureLabelModal/FeatureLabelModal.tsx +++ b/src/FeatureLabelModal/FeatureLabelModal.tsx @@ -1,10 +1,10 @@ import StringUtil from '@terrestris/base-util/dist/StringUtil/StringUtil'; -import { Modal, ModalProps } from 'antd'; +import { InputRef, Modal, ModalProps } from 'antd'; import TextArea from 'antd/lib/input/TextArea'; import Feature from 'ol/Feature'; import Geometry from 'ol/geom/Geometry'; import * as React from 'react'; -import { useEffect, useState } from 'react'; +import { useEffect, useRef, useState } from 'react'; type OwnProps = { feature: Feature; @@ -29,6 +29,8 @@ export const FeatureLabelModal: React.FC = ({ const [label, setLabel] = useState(''); const [showPrompt, setShowPrompt] = useState(false); + const inputRef = useRef(null); + useEffect(() => { if (feature) { setLabel(feature.get('label') ?? ''); @@ -55,12 +57,16 @@ export const FeatureLabelModal: React.FC = ({ closable={false} onOk={onOkInternal} onCancel={onCancel} + afterOpenChange={(open) => { + open && inputRef.current?.focus(); + }} {...passThroughProps} >