-
Notifications
You must be signed in to change notification settings - Fork 3
Add is_sectioning check to Card and Overview
#1936
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
983ffef
Add `is_sectioning` check to Card and Overview
spaceninja d4996b4
add tests
spaceninja de56be3
Create sharp-years-think.md
spaceninja d6e615e
mark properties as private
spaceninja fef623e
add comment about test files
spaceninja 0d0f3e4
Update src/components/card/card.test.ts
spaceninja 1941aaf
Update src/components/card/card.test.ts
spaceninja d3edd76
add comments
spaceninja 7b02ae2
lint
spaceninja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
| --- | ||
| "@cloudfour/patterns": patch | ||
| --- | ||
|
|
||
| Update Card and Overview to only use `header` and `footer` elements if the containing element is an `article` or `section`. |
This file contains hidden or 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,54 @@ | ||
| import path from 'path'; | ||
|
|
||
| import type { ElementHandle } from 'pleasantest'; | ||
| import { getAccessibilityTree, withBrowser } from 'pleasantest'; | ||
|
|
||
| import { loadTwigTemplate } from '../../../test-utils.js'; | ||
|
|
||
| /** Helper to load the Twig template file */ | ||
| const template = loadTwigTemplate(path.join(__dirname, './demo/single.twig')); | ||
| const divTemplate = loadTwigTemplate(path.join(__dirname, './demo/div.twig')); | ||
|
|
||
| describe('Card component', () => { | ||
| test( | ||
| 'should use header/footer with article', | ||
| withBrowser(async ({ utils, page }) => { | ||
| await utils.injectHTML( | ||
| await template({ | ||
| show_heading: true, | ||
| show_footer: true, | ||
| }) | ||
| ); | ||
|
|
||
| const body = await page.evaluateHandle<ElementHandle>( | ||
| () => document.body | ||
| ); | ||
| expect(await getAccessibilityTree(body, { includeText: false })) | ||
| .toMatchInlineSnapshot(` | ||
| article | ||
| banner | ||
| heading "Lorem ipsum dolor sit amet" (level=2) | ||
| contentinfo | ||
| `); | ||
| }) | ||
| ); | ||
|
|
||
| test( | ||
| 'should not use header/footer with div', | ||
| withBrowser(async ({ utils, page }) => { | ||
| await utils.injectHTML( | ||
| await divTemplate({ | ||
| show_heading: true, | ||
| show_footer: true, | ||
| }) | ||
| ); | ||
|
|
||
| const body = await page.evaluateHandle<ElementHandle>( | ||
| () => document.body | ||
| ); | ||
| expect( | ||
| await getAccessibilityTree(body, { includeText: false }) | ||
| ).toMatchInlineSnapshot(`heading "Lorem ipsum dolor sit amet" (level=2)`); | ||
| }) | ||
| ); | ||
| }); |
This file contains hidden or 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
This file contains hidden or 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,23 @@ | ||
| {# Used for tests #} | ||
| {% embed '@cloudfour/components/card/card.twig' with { tag_name: 'div' } %} | ||
spaceninja marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| {% block heading %} | ||
| {%- if show_heading -%} | ||
| Lorem ipsum dolor sit amet | ||
| {%- endif -%} | ||
| {% endblock %} | ||
| {% block cover %} | ||
| {%- if show_cover -%} | ||
| <img src="https://placeimg.com/800/450/animals" alt=""> | ||
| {%- endif -%} | ||
| {% endblock %} | ||
| {% block content %} | ||
| {%- if show_content -%} | ||
| <p>Consectetur adipiscing elit. Fusce tempor ut ex nec scelerisque. Quisque dui tortor, tempus et tempor in, rhoncus eu massa. Vestibulum dolor erat, vestibulum eget velit eu, dignissim hendrerit tortor.</p> | ||
| {%- endif -%} | ||
| {% endblock %} | ||
| {% block footer %} | ||
| {%- if show_footer -%} | ||
| <p>{{'now'|date('M j, Y')}}</p> | ||
| {%- endif -%} | ||
| {% endblock %} | ||
| {% endembed %} | ||
This file contains hidden or 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,12 @@ | ||
| {# Used for tests #} | ||
| {% embed '@cloudfour/objects/overview/overview.twig' with { overview_tag: 'div' } %} | ||
spaceninja marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| {% block header %} | ||
| Header | ||
| {% endblock %} | ||
| {% block actions %} | ||
| Actions | ||
| {% endblock %} | ||
| {% block content %} | ||
| Content | ||
| {% endblock %} | ||
| {% endembed %} | ||
This file contains hidden or 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,56 @@ | ||
| import path from 'path'; | ||
|
|
||
| import type { ElementHandle } from 'pleasantest'; | ||
| import { getAccessibilityTree, withBrowser } from 'pleasantest'; | ||
|
|
||
| import { loadTwigTemplate } from '../../../test-utils.js'; | ||
|
|
||
| /** Helper to load the Twig template file */ | ||
| const template = loadTwigTemplate(path.join(__dirname, './demo/basic.twig')); | ||
| const divTemplate = loadTwigTemplate(path.join(__dirname, './demo/div.twig')); | ||
|
|
||
| describe('Overview object', () => { | ||
| test( | ||
| 'should use header with section', | ||
| withBrowser(async ({ utils, page }) => { | ||
| await utils.injectHTML( | ||
| await template({ | ||
| show_heading: true, | ||
| show_footer: true, | ||
| }) | ||
| ); | ||
|
|
||
| const body = await page.evaluateHandle<ElementHandle>( | ||
| () => document.body | ||
| ); | ||
| expect(await getAccessibilityTree(body)).toMatchInlineSnapshot(` | ||
| region | ||
| banner | ||
| text "Header" | ||
| text "Actions" | ||
| text "Content" | ||
| `); | ||
| }) | ||
| ); | ||
|
|
||
| test( | ||
| 'should not use header with div', | ||
| withBrowser(async ({ utils, page }) => { | ||
| await utils.injectHTML( | ||
| await divTemplate({ | ||
| show_heading: true, | ||
| show_footer: true, | ||
| }) | ||
| ); | ||
|
|
||
| const body = await page.evaluateHandle<ElementHandle>( | ||
| () => document.body | ||
| ); | ||
| expect(await getAccessibilityTree(body)).toMatchInlineSnapshot(` | ||
| text "Header" | ||
| text "Actions" | ||
| text "Content" | ||
| `); | ||
| }) | ||
| ); | ||
| }); |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,14 +1,24 @@ | ||
| <{{overview_tag|default('section')}} | ||
| {% set _overview_tag = overview_tag|default('section') %} | ||
| {# | ||
| Using `header` inside a `div` causes pointless "banner" landmarks in | ||
| the VoiceOver rotor. As a result, we set the default header element | ||
| to `div` if the `overview_tag` is anything but `article` or `section`. | ||
| #} | ||
| {% set _is_sectioning = _overview_tag in ['article', 'section'] %} | ||
| {% set _default_header_tag = _is_sectioning ? 'header' : 'div' %} | ||
| {% set _header_tag_name = header_tag_name|default(_default_header_tag) %} | ||
|
|
||
| <{{ _overview_tag }} | ||
| class="o-overview" | ||
| {% if labelledby_id %}aria-labelledby="{{labelledby_id}}"{% endif %} | ||
| > | ||
| <header class="o-overview__header"> | ||
| <{{ _header_tag_name }} class="o-overview__header"> | ||
| {% block header %}{% endblock %} | ||
| </header> | ||
| </{{ _header_tag_name }}> | ||
| <div class="o-overview__actions"> | ||
| {% block actions %}{% endblock %} | ||
| </div> | ||
| <div class="o-overview__content"> | ||
| {% block content %}{% endblock %} | ||
| </div> | ||
| </{{overview_tag|default('section')}}> | ||
| </{{ _overview_tag }}> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.