Skip to content

Commit

Permalink
Fixed typing in the input field plus the highlight.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieu-fournier committed Jan 3, 2025
1 parent 3d99ce0 commit c389f59
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
21 changes: 21 additions & 0 deletions ui/appui-react/src/appui-react/accudraw/AccuDrawFieldContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,27 @@ export function AccuDrawFieldContainer(props: AccuDrawFieldContainerProps) {
[getInputToFocus]
);

React.useEffect(() => {
// Set the focus to the first input field when the component is mounted and when the compass mode changes.
const itemToFocus =
mode === CompassMode.Polar ? ItemField.DIST_Item : ItemField.X_Item;
IModelApp.accuDraw.setFocusItem(itemToFocus);
setFocusToField(itemToFocus);

const timeoutId = setTimeout(() => {
// Timeout to force an highlight on the field.
const inputToFocus =
mode === CompassMode.Rectangular
? getFieldInput(ItemField.X_Item)
: getFieldInput(ItemField.DIST_Item);
inputToFocus && inputToFocus.focus();
inputToFocus && inputToFocus.select();
}, 1);
return () => {
clearTimeout(timeoutId);
};
}, [mode, setFocusToField]);

React.useEffect(() => {
return FrameworkAccuDraw.onAccuDrawSetFieldLockEvent.addListener((args) => {
switch (args.field) {
Expand Down
14 changes: 2 additions & 12 deletions ui/appui-react/src/appui-react/accudraw/AccuDrawInputField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import "./AccuDrawInputField.scss";
import classnames from "classnames";
import * as React from "react";
import { Key } from "ts-key-enum";
import { ItemField } from "@itwin/core-frontend";
import type { ItemField } from "@itwin/core-frontend";
import type { CommonProps, IconSpec } from "@itwin/core-react";
import { Icon } from "@itwin/core-react";
import { useRefs } from "@itwin/core-react/internal";
Expand Down Expand Up @@ -95,17 +95,7 @@ const ForwardRefAccuDrawInput = React.forwardRef<
const [needSelection, setNeedSelection] = React.useState(false);
const [isFocusField, setIsFocusField] = React.useState(false);
const inputElementRef = React.useRef<HTMLInputElement | null>(null);
const refs = useRefs((instance: HTMLInputElement | null) => {
if (
instance !== null &&
(field === ItemField.DIST_Item || field === ItemField.X_Item)
) {
// Focus the X or Distance input when it's mounted. This also happens when the compass mode changes.
instance.focus();
instance.select();
}
inputElementRef.current = instance;
}, ref); // combine ref needed for target with the forwardRef needed by the Parent when parent is a Type Editor.
const refs = useRefs(inputElementRef, ref); // combine ref needed for target with the forwardRef needed by the Parent when parent is a Type Editor.

const allowBearingLettersInAccuDrawInputFields =
useAllowBearingLettersInAccuDrawInputFields();
Expand Down

0 comments on commit c389f59

Please sign in to comment.