Skip to content

Commit

Permalink
fix: enable drawbutton autofocus on text area
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasLohoff committed Nov 18, 2024
1 parent 5ff6bea commit c39ce54
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 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,16 @@ export const FeatureLabelModal: React.FC<FeatureLabelModalProps> = ({
closable={false}
onOk={onOkInternal}
onCancel={onCancel}
afterOpenChange={(open) => {
open && inputRef.current?.focus();

Check warning on line 61 in src/FeatureLabelModal/FeatureLabelModal.tsx

View workflow job for this annotation

GitHub Actions / build

Expected an assignment or function call and instead saw an expression
}}
{...passThroughProps}
>
<TextArea
value={label}
onChange={e => setLabel(e.target.value)}
autoSize
ref={inputRef}
/>
</Modal>;
};
Expand Down

0 comments on commit c39ce54

Please sign in to comment.