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

[Dashboard] (Accessibility) Adds an H1 tag with the dashboard title #135757

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/plugins/dashboard/public/application/dashboard_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
*/

import { History } from 'history';
import React, { useEffect, useMemo, useState } from 'react';
import React, { useEffect, useMemo, useRef, useState } from 'react';

import { useKibana, useExecutionContext } from '@kbn/kibana-react-plugin/public';

import { useDashboardSelector } from './state';
import { useDashboardAppState } from './hooks';
import {
dashboardFeatureCatalog,
getDashboardBreadcrumb,
getDashboardTitle,
leaveConfirmStrings,
Expand Down Expand Up @@ -49,6 +50,7 @@ export function DashboardApp({
} = useKibana<DashboardAppServices>().services;

const [showNoDataPage, setShowNoDataPage] = useState<boolean>(false);
const dashboardTitleRef = useRef<HTMLHeadingElement>(null);

const kbnUrlStateStorage = useMemo(
() =>
Expand Down Expand Up @@ -76,6 +78,15 @@ export function DashboardApp({
isEmbeddedExternally: Boolean(embedSettings),
});

// focus on the top header when title or view mode is changed
useEffect(() => {
dashboardTitleRef.current?.focus();
}, [dashboardState.title, dashboardState.viewMode]);

const dashboardTitle = useMemo(() => {
return getDashboardTitle(dashboardState.title, dashboardState.viewMode, !savedDashboardId);
}, [dashboardState.title, dashboardState.viewMode, savedDashboardId]);

// Build app leave handler whenever hasUnsavedChanges changes
useEffect(() => {
onAppLeave((actions) => {
Expand Down Expand Up @@ -108,10 +119,10 @@ export function DashboardApp({
},
},
{
text: getDashboardTitle(dashboardState.title, dashboardState.viewMode, !savedDashboardId),
text: dashboardTitle,
},
]);
}, [chrome, dashboardState.title, dashboardState.viewMode, redirectTo, savedDashboardId]);
}, [chrome, dashboardState.title, redirectTo, savedDashboardId, dashboardTitle]);

// clear search session when leaving dashboard route
useEffect(() => {
Expand All @@ -131,6 +142,12 @@ export function DashboardApp({

return (
<>
<h1
id="dashboardTitle"
className="euiScreenReaderOnly"
ref={dashboardTitleRef}
tabIndex={-1}
>{`${dashboardFeatureCatalog.getTitle()} - ${dashboardTitle}`}</h1>
{showNoDataPage && (
<DashboardAppNoDataPage onDataViewCreated={() => setShowNoDataPage(false)} />
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export const getSavedObjects = (): SavedObject[] => [
uiStateJSON: '{}',
version: 1,
visState:
'{"title":"[eCommerce] Markdown","type":"markdown","params":{"fontSize":12,"openLinksInNewTab":false,"markdown":"### Sample eCommerce Data\\nThis dashboard contains sample data for you to play with. You can view it, search it, and interact with the visualizations. For more information about Kibana, check our [docs](https://www.elastic.co/guide/en/kibana/current/index.html)."},"aggs":[]}',
'{"title":"[eCommerce] Markdown","type":"markdown","params":{"fontSize":12,"openLinksInNewTab":false,"markdown":"## Sample eCommerce Data\\nThis dashboard contains sample data for you to play with. You can view it, search it, and interact with the visualizations. For more information about Kibana, check our [docs](https://www.elastic.co/guide/en/kibana/current/index.html)."},"aggs":[]}',
},
coreMigrationVersion: '8.0.0',
id: 'c00d1f90-f5ea-11eb-a78e-83aac3c38a60',
Expand Down
Loading