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} >