Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Default action was not executed after pressing enter on empty modal window 2024.2 #2531

Merged
merged 3 commits into from Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,25 @@
/*
Copyright 2005 - 2024 Advantage Solutions, s. r. o.

This file is part of ORIGAM (http://www.origam.org).

ORIGAM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

ORIGAM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with ORIGAM. If not, see <http://www.gnu.org/licenses/>.
*/

.root {
width: 0;
height: 0;
padding: 0;
border: none;
}
@@ -0,0 +1,52 @@
/*
Copyright 2005 - 2024 Advantage Solutions, s. r. o.

This file is part of ORIGAM (http://www.origam.org).

ORIGAM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

ORIGAM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with ORIGAM. If not, see <http://www.gnu.org/licenses/>.
*/

import React, { useEffect, useRef } from "react";
import { getFormFocusManager } from "model/selectors/DataView/getFormFocusManager";
import { getDataView } from "model/selectors/DataView/getDataView";
import uiActions from "model/actions-ui-tree";
import S from "gui/Workbench/ScreenArea/FormView/BackupFocusPlaceHolder.module.scss";


// This components should get focus if there are no other focusable inputs on the screen section.
// This will ensure that the focus does not stay where we don't expect it to be. For example on
// the parent screen after opening a model window.
export const BackupFocusPlaceHolder = (props: { ctx: any; }) => {
const refInput = useRef<HTMLInputElement>(null);
useEffect(() => {
const focusManager = getFormFocusManager(getDataView(props.ctx));
focusManager.setBackupFocusPlaceHolder(refInput.current);
}, []);

return (
<input
className={S.root}
onKeyDown={(event) => {
if (event.key === "Enter") {
const dataView = getDataView(props.ctx);
if (dataView.firstEnabledDefaultAction) {
uiActions.actions.onActionClick(dataView.firstEnabledDefaultAction)(
event,
dataView.firstEnabledDefaultAction
);
}
}
}}
ref={refInput} />);
};
Expand Up @@ -43,6 +43,7 @@ import { getRowStateForegroundColor } from "model/selectors/RowState/getRowState
import { dimensionsFromProperty, dimensionsFromXmlNode } from "gui/Components/Form/FieldDimensions";
import { findStrings } from "xmlInterpreters/xmlUtils";
import { TabIndex } from "model/entities/TabIndexOwner";
import { BackupFocusPlaceHolder } from "gui/Workbench/ScreenArea/FormView/BackupFocusPlaceHolder";


@inject(({dataView}) => {
Expand Down Expand Up @@ -92,6 +93,7 @@ export class FormBuilder extends React.Component<{
style={{backgroundColor}}
>
{xfo.elements.map((child: any) => recursive(child))}
<BackupFocusPlaceHolder ctx={self.props.dataView}/>
</FormRoot>
);
} else if (xfo.name === "FormElement" && xfo.attributes.Type === "FormSection") {
Expand Down
14 changes: 13 additions & 1 deletion frontend-html/src/model/entities/FormFocusManager.ts
Expand Up @@ -24,6 +24,7 @@ import { getDataView } from "model/selectors/DataView/getDataView";

export class FormFocusManager {
autoFocusDisabled = false;
backupFocusPlaceholder: HTMLInputElement | undefined | null;

private isFormPerspectiveActive(){
const dataView = getDataView(this.parent);
Expand Down Expand Up @@ -61,6 +62,10 @@ export class FormFocusManager {
this.focusableContainers = this.focusableContainers.sort(compareTabIndexOwners);
}

setBackupFocusPlaceHolder(input: HTMLInputElement | null) {
this.backupFocusPlaceholder = input
}

focus(name: string) {
let focusable = this.focusableContainers.find((container) => container.name === name)?.focusable;
this.focusAndRemember(focusable);
Expand All @@ -83,6 +88,12 @@ export class FormFocusManager {
}

forceAutoFocus() {
if (this.focusableContainers.length === 0 && this.backupFocusPlaceholder) {
setTimeout(() => {
this.backupFocusPlaceholder?.focus();
}, 0);
return;
}
const focusable = this.focusableContainers[0].focusable;
if (focusable.disabled) {
// (focusable as any).readOnly returns always false => readonly fields cannot be skipped
Expand All @@ -95,7 +106,8 @@ export class FormFocusManager {
}

autoFocus() {
if (this.focusableContainers.length === 0 || this.autoFocusDisabled || isGlobalAutoFocusDisabled(this.parent)) {
const nothingToFocus = this.focusableContainers.length === 0 && !this.backupFocusPlaceholder;
if (nothingToFocus || this.autoFocusDisabled || isGlobalAutoFocusDisabled(this.parent)) {
return;
}
this.forceAutoFocus();
Expand Down