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

feat(Toc): added additional data-qa attributes inside component #1425

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/components/Toc/Toc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const Toc = React.forwardRef<HTMLElement, TocProps>(function Toc(props, r
content={content}
value={value}
href={href}
qa={qa ? `${qa}-item` : ''}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be undefined by default, empty string results in attribute presence

active={activeValue === value}
onClick={onUpdate}
/>
Expand All @@ -46,6 +47,7 @@ export const Toc = React.forwardRef<HTMLElement, TocProps>(function Toc(props, r
value={childrenValue}
href={childrenHref}
childItem={true}
qa={qa ? `${qa}-item` : ''}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

active={activeValue === childrenValue}
onClick={onUpdate}
/>
Expand Down
15 changes: 13 additions & 2 deletions src/components/Toc/TocItem/TocItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ export interface TocItemProps extends TocItemType {
childItem?: boolean;
active?: boolean;
onClick?: (value: string) => void;
qa?: string;
}

export const TocItem = (props: TocItemProps) => {
const {active = false, childItem = false, content, href, value, onClick} = props;
const {active = false, childItem = false, content, href, value, onClick, qa} = props;

const handleClick = React.useCallback(() => {
if (value === undefined || !onClick) {
Expand Down Expand Up @@ -44,5 +45,15 @@ export const TocItem = (props: TocItemProps) => {
</a>
);

return <div className={b('section', {child: childItem, active})}>{item}</div>;
let testId = '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same


if (qa) {
testId = active ? qa : `${qa}-active`;
}

return (
<div className={b('section', {child: childItem, active})} data-qa={testId}>
{item}
</div>
);
};
Loading