Skip to content

Commit

Permalink
Merge pull request #4120 from terrestris/drawbutton-autofocus
Browse files Browse the repository at this point in the history
Enable drawbutton autofocus on text area
  • Loading branch information
LukasLohoff authored Nov 18, 2024
2 parents f552632 + 898e764 commit 73f0d30
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/FeatureLabelModal/FeatureLabelModal.tsx
Original file line number Diff line number Diff line change
@@ -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<Geometry>;
Expand All @@ -29,6 +29,8 @@ export const FeatureLabelModal: React.FC<FeatureLabelModalProps> = ({
const [label, setLabel] = useState<string>('');
const [showPrompt, setShowPrompt] = useState<boolean>(false);

const inputRef = useRef<InputRef>(null);

useEffect(() => {
if (feature) {
setLabel(feature.get('label') ?? '');
Expand All @@ -55,12 +57,18 @@ export const FeatureLabelModal: React.FC<FeatureLabelModalProps> = ({
closable={false}
onOk={onOkInternal}
onCancel={onCancel}
afterOpenChange={(open) => {
if (open) {
inputRef.current?.focus();
}
}}
{...passThroughProps}
>
<TextArea
value={label}
onChange={e => setLabel(e.target.value)}
autoSize
ref={inputRef}
/>
</Modal>;
};
Expand Down

0 comments on commit 73f0d30

Please sign in to comment.