Skip to content

Commit

Permalink
fix(dotPagination): re-renders breaking keyboard navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
HQFOX authored and zettca committed Aug 4, 2023
1 parent 4cbd9c3 commit d042c6b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 40 deletions.
23 changes: 10 additions & 13 deletions app/src/components/components/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { css } from "@emotion/css";
import styled from "@emotion/styled";
import {
HvDotPagination,
Expand Down Expand Up @@ -54,6 +55,11 @@ export const Pagination = () => {
);
};

const styles = {
container: css({ width: "100%", justifyContent: "center" }),
page: css({ textAlign: "center" }),
};

export const DotPagination = () => {
const [page, setPage] = useState<number>(0);
const pages = [
Expand All @@ -64,20 +70,11 @@ export const DotPagination = () => {
"And finally, this is page 5",
];

const StyledRoot = styled("div")({
width: "100%",
justifyContent: "center",
});

const StyledPage = styled("div")({
textAlign: "center",
});

return (
<StyledRoot>
<StyledPage>
<div className={styles.container}>
<div className={styles.page}>
<HvTypography>{pages[page]}</HvTypography>
</StyledPage>
</div>
<br />
<HvDotPagination
page={page}
Expand All @@ -96,6 +93,6 @@ export const DotPagination = () => {
role="navigation"
aria-label="Example Dot Navigation"
/>
</StyledRoot>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import styled from "@emotion/styled";
import {
CurrentStep,
RadioButtonUnselected,
Expand All @@ -21,6 +20,11 @@ const meta: Meta<typeof HvDotPagination> = {

export default meta;

const styles = {
container: css({ width: "100%", justifyContent: "center" }),
page: css({ textAlign: "center" }),
};

export const Main: StoryObj<HvDotPaginationProps> = {
argTypes: {
classes: { control: { disable: true } },
Expand All @@ -35,20 +39,11 @@ export const Main: StoryObj<HvDotPaginationProps> = {
"And finally, this is page 5",
];

const StyledRoot = styled("div")({
width: "100%",
justifyContent: "center",
});

const StyledPage = styled("div")({
textAlign: "center",
});

return (
<StyledRoot>
<StyledPage>
<div className={styles.container}>
<div className={styles.page}>
<HvTypography>{pages[page]}</HvTypography>
</StyledPage>
</div>
<br />
<HvDotPagination
page={page}
Expand All @@ -67,7 +62,7 @@ export const Main: StoryObj<HvDotPaginationProps> = {
role="navigation"
aria-label="Example Dot Navigation"
/>
</StyledRoot>
</div>
);
},
};
Expand All @@ -92,15 +87,6 @@ export const CustomizedDotPagination: StoryObj<HvDotPaginationProps> = {
"And finally, this is page 5",
];

const StyledRoot = styled("div")({
width: "100%",
justifyContent: "center",
});

const StyledPage = styled("div")({
textAlign: "center",
});

const dotpaginationStyle: HvDotPaginationClasses = {
radioRoot: css({
marginLeft: 0,
Expand All @@ -122,10 +108,10 @@ export const CustomizedDotPagination: StoryObj<HvDotPaginationProps> = {
};

return (
<StyledRoot>
<StyledPage>
<div className={styles.container}>
<div className={styles.page}>
<HvTypography>{pages[page]}</HvTypography>
</StyledPage>
</div>
<br />
<HvDotPagination
classes={dotpaginationStyle}
Expand All @@ -147,7 +133,7 @@ export const CustomizedDotPagination: StoryObj<HvDotPaginationProps> = {
role="navigation"
aria-label="Example Dot Navigation"
/>
</StyledRoot>
</div>
);
},
};

0 comments on commit d042c6b

Please sign in to comment.