-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Heading Check component to own file so I can add to the Page com…
…ponent without making the file too cluttered
- Loading branch information
Showing
2 changed files
with
31 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { ErrorMessageNotification } from "../userMessage/ErrorMessageNotification"; | ||
|
||
/** | ||
* This is for development purposes. It displays an error message when a page is missing an h1 element or has | ||
* one that is configured incorrectly. We will see the error if we create a page that has this issue. | ||
*/ | ||
export const HeadingCheck = () => { | ||
const [error, setError] = useState(""); | ||
|
||
useEffect(() => { | ||
const heading1 = document.querySelector("h1"); | ||
|
||
if (heading1 === null) { | ||
setError("This page is missing an h1 element - please add one with `tabindex=-1`"); | ||
} else { | ||
const missingTabIndex = !(heading1.hasAttribute("tabindex")); | ||
const wrongTabindex = heading1.tabIndex !== -1; | ||
|
||
if (missingTabIndex || wrongTabindex) { | ||
setError("This page's h1 element has a bad `tabindex` - please specify `tabindex=-1`"); | ||
} | ||
} | ||
}, []); | ||
|
||
return (<> | ||
{error && process.env.NODE_ENV !== "production" && <ErrorMessageNotification message={error}/>} | ||
</>); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters