Skip to content

Commit

Permalink
adding aria described by changes
Browse files Browse the repository at this point in the history
  • Loading branch information
anakaren-rojas committed Jul 26, 2024
1 parent 68dd605 commit 18163e8
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
53 changes: 51 additions & 2 deletions __docs__/wonder-blocks-popover/popover.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import Button from "@khanacademy/wonder-blocks-button";
import {View} from "@khanacademy/wonder-blocks-core";
import {Strut} from "@khanacademy/wonder-blocks-layout";
import {color, spacing} from "@khanacademy/wonder-blocks-tokens";
import {LabelLarge} from "@khanacademy/wonder-blocks-typography";
import {HeadingMedium, LabelLarge} from "@khanacademy/wonder-blocks-typography";
import type {Placement} from "@khanacademy/wonder-blocks-tooltip";

import {Popover, PopoverContent} from "@khanacademy/wonder-blocks-popover";
import {Popover, PopoverContent, PopoverContentCore} from "@khanacademy/wonder-blocks-popover";

Check failure on line 12 in __docs__/wonder-blocks-popover/popover.stories.tsx

View workflow job for this annotation

GitHub Actions / Lint (ubuntu-latest, 20.x)

Replace `Popover,·PopoverContent,·PopoverContentCore` with `⏎····Popover,⏎····PopoverContent,⏎····PopoverContentCore,⏎`
import packageConfig from "../../packages/wonder-blocks-popover/package.json";

import ComponentInfo from "../../.storybook/components/component-info";
Expand Down Expand Up @@ -87,6 +87,16 @@ const styles = StyleSheet.create({
flexDirection: "row",
gap: spacing.medium_16,
},
srOnly: {
border: 0,
clip: "rect(0,0,0,0)",
height: 1,
margin: -1,
overflow: "hidden",
padding: 0,
position: "absolute",
width: 1,
},
});

type StoryComponentType = StoryObj<typeof Popover>;
Expand Down Expand Up @@ -742,3 +752,42 @@ export const CustomAriaLabel: StoryComponentType = {
"aria-label": "Popover with custom aria label",
} as PopoverArgs,
};


Check failure on line 756 in __docs__/wonder-blocks-popover/popover.stories.tsx

View workflow job for this annotation

GitHub Actions / Lint (ubuntu-latest, 20.x)

Replace `⏎export·const·CustomAriaDescribedBy·=·({placement}:·{placement:·Placement})·=>·{⏎` with `export·const·CustomAriaDescribedBy·=·({placement}:·{placement:·Placement})·=>·{`
export const CustomAriaDescribedBy = ({placement}: {placement: Placement}) => {

const [opened, setOpened] = React.useState(true);

return (
<View style={styles.example}>
<Popover
aria-label="Popover with custom aria label"
aria-describedby="PopoverTitle"
placement={placement}
opened={opened}
onClose={() => setOpened(false)}
content={
<>
<HeadingMedium id="PopoverTitle" style={styles.srOnly}>Sample text that would describe the navigation of the expression widget</HeadingMedium>

Check failure on line 771 in __docs__/wonder-blocks-popover/popover.stories.tsx

View workflow job for this annotation

GitHub Actions / Lint (ubuntu-latest, 20.x)

Replace `Sample·text·that·would·describe·the·navigation·of·the·expression·widget` with `⏎····························Sample·text·that·would·describe·the·navigation·of⏎····························the·expression·widget⏎························`
<PopoverContentCore

Check failure on line 772 in __docs__/wonder-blocks-popover/popover.stories.tsx

View workflow job for this annotation

GitHub Actions / Lint (ubuntu-latest, 20.x)

Replace `⏎····························closeButtonVisible⏎························` with `·closeButtonVisible`
closeButtonVisible
>
<>

Check failure on line 775 in __docs__/wonder-blocks-popover/popover.stories.tsx

View workflow job for this annotation

GitHub Actions / Lint (ubuntu-latest, 20.x)

Replace `⏎································Popover·Content⏎····························` with `Popover·Content`
Popover Content
</>
</PopoverContentCore>
</>

Check failure on line 779 in __docs__/wonder-blocks-popover/popover.stories.tsx

View workflow job for this annotation

GitHub Actions / Lint (ubuntu-latest, 20.x)

Delete `⏎`

}
>
<Button
onClick={() => {
setOpened(true);
}}
>
{`Open popover`}
</Button>
</Popover>
</View>
);
};
4 changes: 2 additions & 2 deletions packages/wonder-blocks-popover/src/components/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,17 +281,17 @@ export default class Popover extends React.Component<Props, State> {
} = this.props;
const {anchorElement} = this.state;

const ariaDescribedBy = ariaLabel ? undefined : `${uniqueId}-content`;
const ariaDescribedBy = `${uniqueId}-content`;
const ariaLabelledBy = ariaLabel ? undefined : `${uniqueId}-title`;

const popperContent = (
<TooltipPopper anchorElement={anchorElement} placement={placement}>
{(props: PopperElementProps) => (
<PopoverDialog
{...props}
aria-label={ariaLabel}
aria-describedby={ariaDescribedBy}
aria-labelledby={ariaLabelledBy}
aria-label={ariaLabel}
id={uniqueId}
onUpdate={(placement) => this.setState({placement})}
showTail={showTail}
Expand Down

0 comments on commit 18163e8

Please sign in to comment.