Skip to content

Commit de9f7d5

Browse files
committed
Remove isAsync (see #103 (comment) )
1 parent e68e867 commit de9f7d5

File tree

2 files changed

+14
-27
lines changed

2 files changed

+14
-27
lines changed

src/app/routes.tsx

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as React from 'react';
22
import { Route, RouteComponentProps, Switch } from 'react-router-dom';
3-
import { accessibleRouteChangeHandler } from '@app/utils/utils';
43
import { Dashboard } from '@app/Dashboard/Dashboard';
54
import { Support } from '@app/Support/Support';
65
import { GeneralSettings } from '@app/Settings/General/GeneralSettings';
@@ -18,7 +17,6 @@ export interface IAppRoute {
1817
exact?: boolean;
1918
path: string;
2019
title: string;
21-
isAsync?: boolean;
2220
routes?: undefined;
2321
}
2422

@@ -40,7 +38,6 @@ const routes: AppRouteConfig[] = [
4038
{
4139
component: Support,
4240
exact: true,
43-
isAsync: true,
4441
label: 'Support',
4542
path: '/support',
4643
title: 'PatternFly Seed | Support Page',
@@ -69,27 +66,32 @@ const routes: AppRouteConfig[] = [
6966
// a custom hook for sending focus to the primary content container
7067
// after a view has loaded so that subsequent press of tab key
7168
// sends focus directly to relevant content
72-
const useA11yRouteChange = (isAsync: boolean) => {
69+
const useA11yRouteChange = () => {
7370
const lastNavigation = useLastLocation();
7471
React.useEffect(() => {
75-
if (!isAsync && lastNavigation !== null) {
76-
routeFocusTimer = accessibleRouteChangeHandler();
72+
if (lastNavigation !== null) {
73+
routeFocusTimer = window.setTimeout(() => {
74+
const mainContainer = document.getElementById('primary-app-container');
75+
if (mainContainer) {
76+
mainContainer.focus();
77+
}
78+
}, 50);
7779
}
7880
return () => {
7981
window.clearTimeout(routeFocusTimer);
8082
};
81-
}, [isAsync, lastNavigation]);
83+
}, [lastNavigation]);
8284
};
8385

84-
const RouteWithTitleUpdates = ({ component: Component, isAsync = false, title, ...rest }: IAppRoute) => {
85-
useA11yRouteChange(isAsync);
86+
const RouteWithTitleUpdates = ({ component: Component, title, ...rest }: IAppRoute) => {
87+
useA11yRouteChange();
8688
useDocumentTitle(title);
8789

8890
function routeWithTitle(routeProps: RouteComponentProps) {
8991
return <Component {...rest} {...routeProps} />;
9092
}
9193

92-
return <Route render={routeWithTitle} {...rest}/>;
94+
return <Route render={routeWithTitle} {...rest} />;
9395
};
9496

9597
const PageNotFound = ({ title }: { title: string }) => {
@@ -105,15 +107,8 @@ const flattenedRoutes: IAppRoute[] = routes.reduce(
105107
const AppRoutes = (): React.ReactElement => (
106108
<LastLocationProvider>
107109
<Switch>
108-
{flattenedRoutes.map(({ path, exact, component, title, isAsync }, idx) => (
109-
<RouteWithTitleUpdates
110-
path={path}
111-
exact={exact}
112-
component={component}
113-
key={idx}
114-
title={title}
115-
isAsync={isAsync}
116-
/>
110+
{flattenedRoutes.map(({ path, exact, component, title }, idx) => (
111+
<RouteWithTitleUpdates path={path} exact={exact} component={component} key={idx} title={title} />
117112
))}
118113
<PageNotFound title="404 Page Not Found" />
119114
</Switch>

src/app/utils/utils.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)