-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Questions block keyboard access improved (#505)
* feat: improved Questions block accessibility
- Loading branch information
Showing
14 changed files
with
192 additions
and
119 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
42 changes: 42 additions & 0 deletions
42
src/blocks/Questions/QuestionBlockItem/QuestionBlockItem.scss
This file contains 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,42 @@ | ||
@import '../../../../styles/variables'; | ||
@import '../../../../styles/mixins'; | ||
|
||
$block: '.#{$ns}QuestionsBlockItem'; | ||
|
||
#{$block} { | ||
padding-bottom: $indentM; | ||
border-bottom: 1px solid var(--g-color-line-generic); | ||
|
||
& + & { | ||
padding-top: $indentM; | ||
} | ||
|
||
&__title { | ||
@include heading4(); | ||
|
||
position: relative; | ||
padding-right: 24px; | ||
cursor: pointer; | ||
|
||
a { | ||
@include link(); | ||
} | ||
} | ||
|
||
&__arrow { | ||
position: absolute; | ||
right: 0; | ||
top: 0; | ||
color: var(--g-color-text-primary); | ||
} | ||
|
||
&__link { | ||
@include text-size(body-2); | ||
} | ||
|
||
&__text { | ||
@include text-size(body-2); | ||
|
||
margin-top: $indentXXS; | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
src/blocks/Questions/QuestionBlockItem/QuestionBlockItem.tsx
This file contains 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,72 @@ | ||
import React from 'react'; | ||
|
||
import {useActionHandlers} from '@gravity-ui/uikit'; | ||
|
||
import {Foldable, HTML, ToggleArrow, YFMWrapper} from '../../../components'; | ||
import Link from '../../../components/Link/Link'; | ||
import {QuestionBlockItemProps} from '../../../models'; | ||
import {block} from '../../../utils'; | ||
import {FaqMicrodataValues} from '../models'; | ||
|
||
import './QuestionBlockItem.scss'; | ||
|
||
const b = block('QuestionsBlockItem'); | ||
|
||
export const QuestionBlockItem = ({ | ||
title: itemTitle, | ||
text: itemText, | ||
link, | ||
listStyle = 'dash', | ||
isOpened, | ||
onClick, | ||
}: QuestionBlockItemProps) => { | ||
const {onKeyDown} = useActionHandlers(onClick); | ||
|
||
return ( | ||
<div | ||
className={b()} | ||
itemScope | ||
itemProp={FaqMicrodataValues.QuestionProp} | ||
itemType={FaqMicrodataValues.QuestionType} | ||
role={'listitem'} | ||
> | ||
<h3 | ||
className={b('title')} | ||
onClick={onClick} | ||
aria-expanded={isOpened} | ||
role={'button'} | ||
tabIndex={0} | ||
onKeyDown={onKeyDown} | ||
> | ||
<HTML itemProp={FaqMicrodataValues.QuestionNameProp}>{itemTitle}</HTML> | ||
<ToggleArrow | ||
open={isOpened} | ||
size={16} | ||
type={'vertical'} | ||
iconType="navigation" | ||
className={b('arrow')} | ||
/> | ||
</h3> | ||
<Foldable isOpened={isOpened}> | ||
<div | ||
className={b('text')} | ||
itemScope | ||
itemProp={FaqMicrodataValues.AnswerProp} | ||
itemType={FaqMicrodataValues.AnswerType} | ||
aria-hidden={!isOpened} | ||
> | ||
<YFMWrapper | ||
content={itemText} | ||
modifiers={{ | ||
constructor: true, | ||
constructorListStyle: true, | ||
constructorListStyleDash: listStyle === 'dash', | ||
}} | ||
itemProp={FaqMicrodataValues.QuestionTextProp} | ||
/> | ||
{link && <Link {...link} tabIndex={isOpened ? 0 : -1} className={b('link')} />} | ||
</div> | ||
</Foldable> | ||
</div> | ||
); | ||
}; |
This file contains 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 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 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,10 @@ | ||
export const FaqMicrodataValues = { | ||
PageType: 'https://schema.org/FAQPage', | ||
QuestionType: 'https://schema.org/Question', | ||
QuestionProp: 'mainEntity', | ||
QuestionNameProp: 'name', | ||
QuestionTextProp: 'text', | ||
AnswerType: 'https://schema.org/Answer', | ||
AnswerProp: 'acceptedAnswer', | ||
AnswerTextProp: 'text', | ||
} as const; |
This file contains 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 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
Oops, something went wrong.