diff --git a/judo-ui-react/src/main/java/hu/blackbelt/judo/ui/generator/react/UiWidgetHelper.java b/judo-ui-react/src/main/java/hu/blackbelt/judo/ui/generator/react/UiWidgetHelper.java index e94c7da0..d5d68bd8 100644 --- a/judo-ui-react/src/main/java/hu/blackbelt/judo/ui/generator/react/UiWidgetHelper.java +++ b/judo-ui-react/src/main/java/hu/blackbelt/judo/ui/generator/react/UiWidgetHelper.java @@ -126,6 +126,9 @@ public static String justifyContent(Flex flex) { } public static Boolean shouldElementHaveAutoFocus(VisualElement element) { + if (!element.getPageContainer().isForm()) { + return false; + } Input input = findFirstInput(element.getPageContainer()); return input != null && element.getFQName().equals(input.getFQName()); diff --git a/judo-ui-react/src/main/resources/actor/src/config/general.ts.hbs b/judo-ui-react/src/main/resources/actor/src/config/general.ts.hbs index cfef4f9f..74b54a04 100644 --- a/judo-ui-react/src/main/resources/actor/src/config/general.ts.hbs +++ b/judo-ui-react/src/main/resources/actor/src/config/general.ts.hbs @@ -36,3 +36,5 @@ export const fadeTimeout: number = 1200; export const slideTimeout: number = 300; export const dialogStackCloseDelay: number = 50; + +export const autoFocusRefDelay: number = 200; diff --git a/judo-ui-react/src/main/resources/actor/src/containers/container.tsx.hbs b/judo-ui-react/src/main/resources/actor/src/containers/container.tsx.hbs index 94215b7e..9b02450c 100644 --- a/judo-ui-react/src/main/resources/actor/src/containers/container.tsx.hbs +++ b/judo-ui-react/src/main/resources/actor/src/containers/container.tsx.hbs @@ -101,6 +101,19 @@ export default function {{ containerComponentName container }}(props: {{ contain const { service: customContainerHook } = useTrackService<{{ containerComponentName container }}ContainerHook>(`(${OBJECTCLASS}=${ {{~ camelCaseNameToInterfaceKey (containerComponentName container) }}_CONTAINER_ACTIONS_HOOK_INTERFACE_KEY})`); const containerActions: {{ pageContainerActionDefinitionTypeName container }} = customContainerHook?.({{# unless container.table }}data, editMode, storeDiff{{/ unless }}) || {}; const actions = useMemo(() => ({...containerActions, ...pageActions}), [containerActions, pageActions]); + {{# if container.form }} + const autoFocusInputRef = useRef(null); + + useEffect(() => { + const timeout = setTimeout(() => { + if (typeof autoFocusInputRef?.current?.focus === 'function') { + autoFocusInputRef.current.focus(); + } + }, autoFocusRefDelay); + + return () => clearTimeout(timeout); + }, []); + {{/ if }} {{/ unless }} return ( diff --git a/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/dateinput.hbs b/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/dateinput.hbs index c5843ee4..77260e67 100644 --- a/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/dateinput.hbs +++ b/judo-ui-react/src/main/resources/actor/src/containers/widget-fragments/dateinput.hbs @@ -13,7 +13,7 @@ {{/ if }}