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

🔧 Page h1 focusability #1428

Merged
merged 4 commits into from
Jul 21, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/Nri/Ui/Page/V3.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@ module Nri.Ui.Page.V3 exposing
( httpError
, DefaultPage, broken, blockedV4, blocked, notFound, noPermission, loggedOut, timeOut, networkError
, RecoveryText(..)
, headingId
)

{-| A styled NRI page!
{-| Patch changes:

- added `headingId` as the `id` of the `h1` produced by `Page`
- made the `h1` produced by `Page` programmatically focusable

A styled NRI error page.

@docs httpError
@docs DefaultPage, broken, blockedV4, blocked, notFound, noPermission, loggedOut, timeOut, networkError
@docs RecoveryText
@docs headingId

-}

import Accessibility.Styled.Key as Key
import Css exposing (..)
import Html.Styled as Html exposing (Html)
import Html.Styled.Attributes as Attributes
Expand Down Expand Up @@ -185,6 +193,14 @@ httpError error defaultPage =
blockedV4 body defaultPage


{-| This ID is attached to the `h1` produced by Page.
This can be useful when you need to move focus to the heading to communicate to AT users that there's been an error.
-}
headingId : String
headingId =
"nri-ui-page-heading-h1"



-- INTERNAL

Expand All @@ -206,6 +222,8 @@ view config =
, Heading.h1
[ Heading.plaintext config.title
, Heading.css [ Css.textAlign Css.center ]
, Heading.id headingId
, Heading.custom [ Key.tabbable False ]
]
, Text.mediumBody
[ Text.plaintext config.subtitle
Expand Down
29 changes: 21 additions & 8 deletions tests/Spec/Nri/Ui/Page.elm
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
module Spec.Nri.Ui.Page exposing (all)

import Accessibility.Key as Key
import Expect
import Html.Styled as Html
import Nri.Ui.Page.V3 as Page
import Test exposing (..)
import Test.Html.Query as Query
import Test.Html.Selector exposing (..)


type Msg
= NoOp
import Test.Html.Selector as Selector exposing (..)


all : Test
Expand All @@ -19,7 +16,7 @@ all =
[ test "handles recovery text for ReturnTo" <|
\() ->
Page.notFound
{ link = NoOp
{ link = ()
, recoveryText = Page.ReturnTo "the main page"
}
|> Html.toUnstyled
Expand All @@ -29,7 +26,7 @@ all =
, test "handles recovery text for Reload" <|
\() ->
Page.notFound
{ link = NoOp
{ link = ()
, recoveryText = Page.Reload
}
|> Html.toUnstyled
Expand All @@ -39,12 +36,28 @@ all =
, test "handles recovery text for Custom" <|
\() ->
Page.notFound
{ link = NoOp
{ link = ()
, recoveryText = Page.Custom "cats"
}
|> Html.toUnstyled
|> Query.fromHtml
|> Expect.all
[ Query.has [ text "cats" ] ]
, test "heading is focusable" <|
\() ->
Page.notFound
{ link = ()
, recoveryText = Page.Reload
}
|> Html.toUnstyled
|> Query.fromHtml
|> Expect.all
[ Query.has
[ Selector.all
[ id Page.headingId
, attribute (Key.tabbable False)
]
]
]
]
]
Loading