Skip to content

Commit

Permalink
Fix/navigation main content (#1843)
Browse files Browse the repository at this point in the history
* fix: do not focus on main content when first loading the page

* change focus to main on task submit

* remove focus-visible from main-content
  • Loading branch information
mikaelrss authored Feb 21, 2024
1 parent 7293d6e commit 1ef1d0e
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/components/wrappers/Presentation.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@
.modalBody {
padding: var(--modal-padding-y) var(--modal-padding-x);
}

.modal:focus-visible {
outline: none;
}
2 changes: 2 additions & 0 deletions src/features/formData/submit/submitFormDataSagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { staticUseLanguageFromState } from 'src/hooks/useLanguage';
import { makeGetAllowAnonymousSelector } from 'src/selectors/getAllowAnonymous';
import { getCurrentDataTypeForApplication, getCurrentTaskDataElementId, isStatelessApp } from 'src/utils/appMetadata';
import { convertDataBindingToModel, convertModelToDataBinding, filterOutInvalidData } from 'src/utils/databindings';
import { focusMainContent } from 'src/utils/formLayout';
import { ResolvedNodesSelector } from 'src/utils/layout/hierarchy';
import { httpPost } from 'src/utils/network/networking';
import { httpGet, httpPut } from 'src/utils/network/sharedNetworking';
Expand Down Expand Up @@ -52,6 +53,7 @@ export function* submitFormSaga(): SagaIterator {
yield call(putFormData, {});
yield call(submitComplete, state, resolvedNodes);
yield put(FormDataActions.submitFulfilled());
focusMainContent();
} catch (error) {
window.logError('Submit form data failed:\n', error);
yield put(FormDataActions.submitRejected({ error }));
Expand Down
6 changes: 6 additions & 0 deletions src/features/layout/fetch/fetchFormLayoutSagas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ describe('fetchFormLayoutSagas', () => {
FormLayoutActions.updateCurrentView({
newView: 'page1',
skipPageCaching: true,
skipFocusMainContent: true,
}),
)
.run();
Expand All @@ -129,6 +130,7 @@ describe('fetchFormLayoutSagas', () => {
FormLayoutActions.updateCurrentView({
newView: 'FormLayout',
skipPageCaching: true,
skipFocusMainContent: true,
}),
)
.run();
Expand Down Expand Up @@ -179,6 +181,7 @@ describe('fetchFormLayoutSagas', () => {
FormLayoutActions.updateCurrentView({
newView: 'page2',
skipPageCaching: true,
skipFocusMainContent: true,
}),
)
.run();
Expand Down Expand Up @@ -211,6 +214,7 @@ describe('fetchFormLayoutSagas', () => {
FormLayoutActions.updateCurrentView({
newView: 'page1',
skipPageCaching: true,
skipFocusMainContent: true,
}),
)
.run();
Expand All @@ -237,6 +241,7 @@ describe('fetchFormLayoutSagas', () => {
FormLayoutActions.updateCurrentView({
newView: 'page1',
skipPageCaching: true,
skipFocusMainContent: true,
}),
)
.run();
Expand All @@ -263,6 +268,7 @@ describe('fetchFormLayoutSagas', () => {
FormLayoutActions.updateCurrentView({
newView: 'page1',
skipPageCaching: true,
skipFocusMainContent: true,
}),
)
.run();
Expand Down
1 change: 1 addition & 0 deletions src/features/layout/fetch/fetchFormLayoutSagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export function* fetchLayoutSaga(): SagaIterator {
FormLayoutActions.updateCurrentView({
newView: firstLayoutKey,
skipPageCaching: true,
skipFocusMainContent: true,
}),
);
} catch (error) {
Expand Down
5 changes: 4 additions & 1 deletion src/features/layout/formLayoutSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
} from 'src/features/layout/update/updateFormLayoutSagas';
import { OptionsActions } from 'src/features/options/optionsSlice';
import { createSagaSlice } from 'src/redux/sagaSlice';
import { focusMainContent } from 'src/utils/formLayout';
import type * as LayoutTypes from 'src/features/layout/formLayoutTypes';
import type { ILayouts } from 'src/layout/layout';
import type { ActionsFromSlice, MkActionType } from 'src/redux/sagaSlice';
Expand Down Expand Up @@ -169,7 +170,9 @@ export const formLayoutSlice = () => {
takeEvery: (action) => {
if (!action.payload.focusComponentId) {
window.scrollTo({ top: 0 });
document.getElementById('main-content')?.focus({ preventScroll: true });
if (action.payload.skipFocusMainContent !== true) {
focusMainContent();
}
}
},
reducer: (state, action) => {
Expand Down
2 changes: 2 additions & 0 deletions src/features/layout/formLayoutTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface IUpdateCurrentView {
returnToView?: string;
runValidations?: TriggersPageValidation;
skipPageCaching?: boolean;
skipFocusMainContent?: boolean;
focusComponentId?: string;
keepScrollPos?: IKeepComponentScrollPos;
allowNavigationToHidden?: boolean;
Expand All @@ -47,6 +48,7 @@ export interface IUpdateCurrentViewFulfilled {
newView: string;
returnToView?: string;
focusComponentId?: string;
skipFocusMainContent?: boolean;
}

export interface IUpdateCurrentViewRejected extends IFormLayoutActionRejected {
Expand Down
2 changes: 2 additions & 0 deletions src/features/layout/update/updateFormLayoutSagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export function* updateCurrentViewSaga({
keepScrollPos,
focusComponentId,
allowNavigationToHidden,
skipFocusMainContent,
},
}: PayloadAction<IUpdateCurrentView>): SagaIterator {
try {
Expand Down Expand Up @@ -102,6 +103,7 @@ export function* updateCurrentViewSaga({
newView,
returnToView,
focusComponentId,
skipFocusMainContent,
}),
);
} else {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/formLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,3 +408,7 @@ export function getRepeatingGroupFilteredIndices(formData: IFormData, filter?: I
}
return null;
}

export function focusMainContent() {
document.getElementById('main-content')?.focus({ preventScroll: true });
}

0 comments on commit 1ef1d0e

Please sign in to comment.