Skip to content

Commit

Permalink
feat: added delayed auto-focus on name field for NewComponentModal an…
Browse files Browse the repository at this point in the history
…d NewPageModal

GitOrigin-RevId: fe3409c909f84fad36516b131f91fb579316980c
  • Loading branch information
abbas-nazar authored and actions-user committed Oct 16, 2024
1 parent 62b8579 commit e3ad573
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ function NewComponentModal(props: NewComponentModalProps) {
nameInput={{
props: {
autoFocus: true,
isDelayedFocus: true,
"data-test-id": "prompt",
ref: nameRef,
value: name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function NewPageModal(props: NewPageModalProps) {
const [projectId, setProjectId] = React.useState<string | undefined>(
undefined
);
const [name, setName] = React.useState("NewPage");
const [name, setName] = React.useState("");
const nameRef = React.useRef<TextboxRef>(null);

const isApp = studioCtx.siteInfo.hasAppAuth;
Expand Down Expand Up @@ -73,6 +73,7 @@ function NewPageModal(props: NewPageModalProps) {
nameInput={{
props: {
autoFocus: true,
isDelayedFocus: true,
"data-test-id": "prompt",
ref: nameRef,
value: name,
Expand Down
9 changes: 8 additions & 1 deletion platform/wab/src/wab/client/components/widgets/Textbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type TextboxProps = Omit<React.ComponentProps<"input">, "disabled"> & {
skipEditOnBlur?: boolean;
selectAllOnAutoFocus?: boolean;
selectAllOnFocus?: boolean;
isDelayedFocus?: boolean;
children?: never;
wrapperProps?: React.ComponentProps<"div">;
};
Expand Down Expand Up @@ -107,7 +108,13 @@ export const Textbox = React.forwardRef(
//
// So we manually focus just in case.
if (props.autoFocus) {
focus();
if (props?.isDelayedFocus) {
setTimeout(() => {
focus();
}, 300);
} else {
focus();
}
}
});

Expand Down

0 comments on commit e3ad573

Please sign in to comment.