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

fix(PageLayout): restore main landmark #3737

Merged
merged 2 commits into from
Sep 13, 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
7 changes: 7 additions & 0 deletions .changeset/friendly-shirts-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@primer/react': patch
---

Restore default main landmark in PageLayout.Content

<!-- Changed components: PageLayout, SplitPageLayout -->
19 changes: 14 additions & 5 deletions src/PageLayout/PageLayout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ describe('PageLayout', () => {
<ThemeProvider>
<PageLayout>
<PageLayout.Header>Header</PageLayout.Header>
<PageLayout.Content>
<main aria-label="Content">Content</main>
</PageLayout.Content>
<PageLayout.Content>Content</PageLayout.Content>
<PageLayout.Pane>Pane</PageLayout.Pane>
<PageLayout.Footer>Footer</PageLayout.Footer>
</PageLayout>
Expand Down Expand Up @@ -133,7 +131,7 @@ describe('PageLayout', () => {
)

expect(screen.getByRole('banner')).toHaveAccessibleName('Header')
expect(screen.getByLabelText('Content')).toHaveAccessibleName('Content')
expect(screen.getByRole('main')).toHaveAccessibleName('Content')
expect(screen.getByRole('contentinfo')).toHaveAccessibleName('Footer')
})

Expand All @@ -156,7 +154,7 @@ describe('PageLayout', () => {
)

expect(screen.getByRole('banner')).toHaveAccessibleName('header')
expect(screen.getByLabelText('content')).toBeInTheDocument()
expect(screen.getByRole('main')).toHaveAccessibleName('content')
expect(screen.getByRole('contentinfo')).toHaveAccessibleName('footer')
})

Expand Down Expand Up @@ -202,4 +200,15 @@ describe('PageLayout', () => {
expect(finalWidth).not.toEqual(initialWidth)
})
})

describe('PageLayout.Content', () => {
it('should support a custom element type with the `as` prop', () => {
const {container} = render(
<PageLayout.Content as="div">
<main>Content</main>
</PageLayout.Content>,
)
expect(container.firstChild?.nodeName).toEqual('DIV')
})
})
})
8 changes: 8 additions & 0 deletions src/PageLayout/PageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,12 @@ Header.displayName = 'PageLayout.Header'
// PageLayout.Content

export type PageLayoutContentProps = {
/**
* Provide an optional element type for the outermost element rendered by the component.
* @default 'main'
*/
as?: React.ElementType

/**
* A unique label for the rendered main landmark
*/
Expand All @@ -408,6 +414,7 @@ const contentWidths = {
}

const Content: React.FC<React.PropsWithChildren<PageLayoutContentProps>> = ({
as = 'main',
'aria-label': label,
'aria-labelledby': labelledBy,
width = 'full',
Expand All @@ -421,6 +428,7 @@ const Content: React.FC<React.PropsWithChildren<PageLayoutContentProps>> = ({

return (
<Box
as={as}
aria-label={label}
aria-labelledby={labelledBy}
sx={merge<BetterSystemStyleObject>(
Expand Down
22 changes: 9 additions & 13 deletions src/PageLayout/__snapshots__/PageLayout.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ exports[`PageLayout renders condensed layout 1`] = `
<div
class="c5"
>
<div
<main
class="c6"
>
<div
Expand All @@ -213,7 +213,7 @@ exports[`PageLayout renders condensed layout 1`] = `
<div
class=""
/>
</div>
</main>
<div
class="c8"
>
Expand Down Expand Up @@ -493,7 +493,7 @@ exports[`PageLayout renders default layout 1`] = `
<div
class="c5"
>
<div
<main
class="c6"
>
<div
Expand All @@ -502,16 +502,12 @@ exports[`PageLayout renders default layout 1`] = `
<div
class="c7"
>
<main
aria-label="Content"
>
Content
</main>
Content
</div>
<div
class=""
/>
</div>
</main>
<div
class="c8"
>
Expand Down Expand Up @@ -791,7 +787,7 @@ exports[`PageLayout renders pane in different position when narrow 1`] = `
<div
class="c5"
>
<div
<main
class="c6"
>
<div
Expand All @@ -805,7 +801,7 @@ exports[`PageLayout renders pane in different position when narrow 1`] = `
<div
class=""
/>
</div>
</main>
<div
class="c8"
>
Expand Down Expand Up @@ -1085,7 +1081,7 @@ exports[`PageLayout renders with dividers 1`] = `
<div
class="c5"
>
<div
<main
class="c6"
>
<div
Expand All @@ -1099,7 +1095,7 @@ exports[`PageLayout renders with dividers 1`] = `
<div
class=""
/>
</div>
</main>
<div
class="c8"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ exports[`SplitPageLayout renders default layout 1`] = `
<div
class="c5"
>
<div
<main
class="c6"
>
<div
Expand All @@ -248,7 +248,7 @@ exports[`SplitPageLayout renders default layout 1`] = `
<div
class=""
/>
</div>
</main>
<div
class="c8"
>
Expand Down
Loading