Skip to content

Commit

Permalink
fix: fix a11y, mock router in stories
Browse files Browse the repository at this point in the history
  • Loading branch information
aeksandla committed Feb 16, 2024
1 parent 6f48cd1 commit 34613bc
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/blocks/Feed/Feed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const Feed = ({image}: FeedProps) => {
...value,
};

router?.updateQueryCallback?.(result);
router.updateQueryCallback(result);
},
[router],
);
Expand Down
9 changes: 8 additions & 1 deletion src/blocks/Feed/__stories__/Feed.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {Feed} from '../Feed';
import mockedPosts from '../../../../.mocks/posts.json';
import mockedServices from '../../../../.mocks/services.json';
import mockedTags from '../../../../.mocks/tags.json';
import {RouterContext} from '../../../contexts/RouterContext';
import {routerData} from '../../../demo/mocks';

export default {
title: 'Blocks/Feed',
Expand Down Expand Up @@ -76,7 +78,12 @@ const contextData = {

const DefaultTemplate: StoryFn<FeedModel> = (args) => (
<FeedContext.Provider value={contextData as unknown as FeedContextProps}>
<PageConstructor content={{blocks: [args] as unknown as Block[]}} custom={customBlocks} />
<RouterContext.Provider value={routerData}>
<PageConstructor
content={{blocks: [args] as unknown as Block[]}}
custom={customBlocks}
/>
</RouterContext.Provider>
</FeedContext.Provider>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ $clearIconSize: 11px;
position: absolute;
inset: 0;
border-radius: var(--g-border-radius-xl);
background: transparent;
border: none;
cursor: pointer;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ export const CustomSwitcher = ({
const hasCounter = itemsNames.length > 1;

return (
<button
<div

Check failure on line 46 in src/components/FeedHeader/components/CustomSwitcher/CustomSwitcher.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Avoid non-native interactive elements. If using native HTML is not possible, add an appropriate role and support for tabbing, mouse, keyboard, and touch inputs to an interactive content element
className={b('custom-switcher')}
ref={controlRef as LegacyRef<HTMLButtonElement>}
ref={controlRef as LegacyRef<HTMLDivElement>}
onKeyDown={onKeyDown}
aria-expanded={open}
>
<div onClick={onClick} className={b('custom-switcher-element', {overlay: true})} />
<button onClick={onClick} className={b('custom-switcher-element', {overlay: true})} />
<div className={b('custom-switcher-element', {content: true})}>
{itemsNames?.join(', ')}
</div>
Expand All @@ -67,6 +67,6 @@ export const CustomSwitcher = ({
<div className={b('custom-switcher-element', {arrow: true})}>
<Icon data={DropdownArrow} size={ICON_SIZE} className={b('switcher-arrow')} />
</div>
</button>
</div>
);
};
12 changes: 2 additions & 10 deletions src/containers/BlogPage/__stories__/BlogPage.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import type {Meta, StoryContext, StoryFn} from '@storybook/react';

import {BlogConstructorProvider} from '../../../constructor/BlogConstructorProvider';
import {GetPostsRequest, Query} from '../../../models/common';
import {GetPostsRequest} from '../../../models/common';
import {BlogPage, BlogPageProps} from '../BlogPage';

import page from '../../../../.mocks/blogPage.json';
Expand All @@ -12,17 +12,9 @@ import posts from '../../../../.mocks/posts.json';
import services from '../../../../.mocks/services.json';
import tags from '../../../../.mocks/tags.json';
import {Lang} from '../../../models/locale';
import {routerData} from '../../../demo/mocks';

const mockMetaComponent = <title>Blog page</title>;
const routerData = {
as: '/',
pathname: '/',
hostname: 'host',
query: {},
updateQueryCallback: (params: Query) => {
console.log('params', params);
},
};

export default {
title: 'Containers/BlogPage',
Expand Down
11 changes: 11 additions & 0 deletions src/demo/mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {Query} from '../models/common';

export const routerData = {
as: '/',
pathname: '/',
hostname: 'host',
query: {},
updateQueryCallback: (params: Query) => {
console.log('params', params);

Check warning on line 9 in src/demo/mocks.ts

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected console statement
},
};

0 comments on commit 34613bc

Please sign in to comment.