-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Heading
: refactor away from the createComponent
function, fix TS errors
#34921
Heading
: refactor away from the createComponent
function, fix TS errors
#34921
Conversation
Heading
: refactor away from the createComponent
function, fix TS …Heading
: refactor away from the createComponent
function, fix TS errors
@@ -25,7 +25,7 @@ export interface HeadingProps extends Omit< TextProps, 'size' > { | |||
/** | |||
* `Heading` will typically render the sizes `1`, `2`, `3`, `4`, `5`, or `6`, which map to `h1`-`h6`. | |||
* | |||
* @default 3 | |||
* @default 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the useHeading
hook (defined in this same file), the default value of level
is 2
@@ -56,16 +56,17 @@ export function useHeading( | |||
'Heading' | |||
); | |||
|
|||
const as = asProp || `h${ level }`; | |||
const as = ( asProp || `h${ level }` ) as keyof JSX.IntrinsicElements; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Necessary to avoid a TypeScript error when passing this computed as
prop to the View
component
'aria-level'?: number; | ||
} = {}; | ||
if ( typeof as === 'string' && as[ 0 ] !== 'h' ) { | ||
// if not a semantic `h` element, add a11y props: | ||
a11yProps.role = 'heading'; | ||
a11yProps[ 'aria-level' ] = level; | ||
a11yProps[ 'aria-level' ] = | ||
typeof level === 'string' ? parseInt( level ) : level; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix a TypeScript error where the expected value of aria-level
can only be number | undefined
(and not string
)
Description
Fixes partially #34920.
How has this been tested?
Technically there should be no behavioral changes.
The project should build, the tests should pass, the component should behave as before in Storybook and in the block editor.
Types of changes
Refactor
Checklist:
*.native.js
files for terms that need renaming or removal).