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

Add heading component #98

Closed
mjbp opened this issue Dec 2, 2021 · 2 comments
Closed

Add heading component #98

mjbp opened this issue Dec 2, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@mjbp
Copy link
Contributor

mjbp commented Dec 2, 2021

To codify the solution to the known VoiceOver (VO) issue, where an <h1> is announced as two <h1>s because the copy had additional markup inside.

For example: VO reads <h1>AX <em>for all</em></h1> as "AX heading level 1, for all heading level 1"

The solution is to wrap the inner content of the <h1> in a span like this:
<h1><span role="text">AX <em>for all</em></span></h1> which VO then announces as "AX for all heading level 1"

References
https://axesslab.com/text-splitting/
https://dequeuniversity.com/rules/axe/4.3/aria-text

The component could be a single Heading accepting a level prop:

import { h, toChildArray } from 'preact';

const Heading = ({ level = 1, children, className }) => {

    const Tag = `h${level}`;
    return  <Tag class={className}>
            {
                toChildArray(children).length > 1
                    ? <span role="text">{children}</span>
                    : children
                
            }
        </Tag>;
};
export default Heading;

or 6 separate Headings <H1>, <H2>, etc:

const H1 = ({ children, className }) => <h1 class={className}>
            {
                toChildArray(children).length > 1
                    ? <span role="text">{children}</span>
                    : children
                
            }
        </h1>;

export default H1 ;

or both with H1, H2, etc as higher order components that use Heading:

import { h } from 'preact';
import Heading from '@components/heading';

const H1 = ({ className, children }) => <Heading level={1} className={className}>{children}</Heading>;

export default H1;

@mjbp mjbp added the enhancement New feature or request label Dec 2, 2021
@Nick-StormID
Copy link
Contributor

I prefer the single Heading approach, to more clearly distinguish this component from standard markup.
I think this would make the initial decision to use the component more conscious and, in support, make it more transparent that a component, not standard markup, was being used.

Nick-StormID added a commit that referenced this issue Jan 5, 2022
mjbp pushed a commit that referenced this issue Jan 6, 2022
* Initial Image component developement

* v2 Image component

* v2 Figure

* Accessibility example

* v3 BEM and light refactor

* Removed unused versions and assets. Moved notes to DOCS file

* Removed redundant ternaries. Added separate class for caption

* #98 - Cleaned up per PR comments
@mjbp
Copy link
Contributor Author

mjbp commented Mar 18, 2022

Closed with #99

@mjbp mjbp closed this as completed Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants