11import React , { useContext , useMemo } from 'react' ;
2-
32import { CardBase , HTML , MetrikaGoal , YFMWrapper } from '@gravity-ui/page-constructor' ;
3+ import { useUniqId } from '@gravity-ui/uikit' ;
44
55import { LikesContext } from '../../contexts/LikesContext' ;
66import { PostCardSize , PostCardTitleHeadingLevel , PostData } from '../../models/common' ;
77import { block } from '../../utils/cn' ;
88import { SuggestPostInfo } from '../PostInfo/SuggestPostInfo' ;
9+ import { useAriaAttributes } from '../../hooks/useAriaAttributes' ;
910
1011import './PostCard.scss' ;
1112
@@ -62,22 +63,43 @@ export const PostCard = ({
6263 : undefined ,
6364 [ hasUserLike , likes , toggleLike , hasLikes ] ,
6465 ) ;
66+ const titleId = useUniqId ( ) ;
67+ const descriptionId = useUniqId ( ) ;
68+ const dateId = useUniqId ( ) ;
69+ const tagId = useUniqId ( ) ;
70+ const readingTimeId = useUniqId ( ) ;
71+ const isTagVisible = showTag && tags ?. [ 0 ] ?. name ;
72+ const ariaAttributes = useAriaAttributes ( {
73+ labelIds : [ isTagVisible && tagId , title && titleId ] ,
74+ descriptionIds : [
75+ description && descriptionId ,
76+ date && dateId ,
77+ readingTime && readingTimeId ,
78+ ] ,
79+ } ) ;
6580
6681 return (
67- < CardBase url = { url } metrikaGoals = { metrikaGoals } className = { b ( 'card' , { fullWidth} ) } >
82+ < CardBase
83+ url = { url }
84+ metrikaGoals = { metrikaGoals }
85+ className = { b ( 'card' , { fullWidth} ) }
86+ extraProps = { ariaAttributes }
87+ >
6888 < CardBase . Header image = { image } className = { b ( 'header' , { fullWidth} ) } >
6989 < div className = { b ( 'image-container' ) } data-qa = "blog-suggest-header" />
7090 </ CardBase . Header >
7191 < CardBase . Content >
72- { showTag && tags ?. [ 0 ] ?. name && (
73- < div className = { b ( 'tag' , { size} ) } > { tags [ 0 ] . name } </ div >
92+ { isTagVisible && (
93+ < div id = { tagId } className = { b ( 'tag' , { size} ) } >
94+ { tags [ 0 ] . name }
95+ </ div >
7496 ) }
7597 { title &&
7698 React . createElement (
7799 titleHeadingLevel ,
78100 { className : b ( 'title' , { size} ) } ,
79101 < span >
80- < HTML > { title } </ HTML >
102+ < HTML id = { titleId } > { title } </ HTML >
81103 </ span > ,
82104 ) }
83105 { description && (
@@ -88,6 +110,7 @@ export const PostCard = ({
88110 blog : size === 'm' ,
89111 blogCard : true ,
90112 } }
113+ id = { descriptionId }
91114 />
92115 ) }
93116 </ CardBase . Content >
@@ -100,6 +123,8 @@ export const PostCard = ({
100123 likes = { likesProps }
101124 size = { size }
102125 qa = "blog-suggest-block"
126+ dateId = { dateId }
127+ readingTimeId = { readingTimeId }
103128 />
104129 </ CardBase . Footer >
105130 </ CardBase >
0 commit comments