Skip to content

Commit

Permalink
fix: using aria labelledby
Browse files Browse the repository at this point in the history
  • Loading branch information
kkmch committed Nov 7, 2023
1 parent e68d12d commit a7af280
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
},
"dependencies": {
"@gravity-ui/icons": "^2.5.0",
"@gravity-ui/uikit": "^5.12.2",
"@gravity-ui/uikit": "^5.19.0",
"@popperjs/core": "^2.11.2",
"bem-cn-lite": "4.1.0",
"i18next": "^19.9.2",
Expand Down
15 changes: 11 additions & 4 deletions src/components/Toc/Toc.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';

import {getUniqId} from '@gravity-ui/uikit';
import block from 'bem-cn-lite';
import {omit} from 'lodash';

Expand Down Expand Up @@ -45,11 +46,13 @@ class Toc extends React.Component<TocProps, TocState> {

containerEl: HTMLElement | null = null;
footerEl: HTMLElement | null = null;
tocTopId: string;

constructor(props: TocProps) {
super(props);

this.state = this.computeState(this.getInitialState());
this.tocTopId = getUniqId();
}

getInitialState() {
Expand Down Expand Up @@ -153,7 +156,7 @@ class Toc extends React.Component<TocProps, TocState> {

private renderList = (items: TocItem[]) => {
const {toggleItem} = this;
const {singlePage, title} = this.props;
const {singlePage} = this.props;
const {activeId, fixedById} = this.state;

const activeItem = activeId && this.state.registry.getItemById(activeId);
Expand All @@ -162,7 +165,7 @@ class Toc extends React.Component<TocProps, TocState> {
: {};

return (
<ul className={b('list')} aria-label={title}>
<ul className={b('list')} aria-labelledby={this.tocTopId}>
{items.map((item, index) => {
const main = !this.state.registry.getParentId(item.id);
const active =
Expand Down Expand Up @@ -233,8 +236,12 @@ class Toc extends React.Component<TocProps, TocState> {
}

return (
<div className={b('top', {scrolled: contentScrolled})}>
{tocTitleIcon ? <div className={b('top-header-icon')}>{tocTitleIcon}</div> : null}
<div className={b('top', {scrolled: contentScrolled})} id={this.tocTopId}>
{tocTitleIcon ? (
<div className={b('top-header-icon')} aria-hidden={'true'}>
{tocTitleIcon}
</div>
) : null}
{topHeader}
</div>
);
Expand Down

0 comments on commit a7af280

Please sign in to comment.