Skip to content

Commit

Permalink
TPP-849 accessibility for floatin UI (#314)
Browse files Browse the repository at this point in the history
* fixed accessability issues

* 3.2.20
  • Loading branch information
KitoC authored Aug 7, 2024
1 parent 92aeab6 commit e60621b
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 69 deletions.
51 changes: 26 additions & 25 deletions lib/components/ActionsMenu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ const crossTransform2 = keyframes`
const StyledActionsMenuContainer = styled.div`
pointer-events: none;
opacity: 0;
transition: all 300ms;
transition-timing-function: cubic-bezier(0, 1.4, 1, 1);
&.visible {
opacity: 1;
Expand Down Expand Up @@ -186,12 +184,12 @@ export const ActionsMenuHeading = styled((props) => {
`;

export const ActionsMenuItem = styled((props) => {
const { id, onItemClick } = useContext(ActionMenuContext);
const { id, onItemClick, actionMenu } = useContext(ActionMenuContext);

const { as, ...others } = props;
const Component = as ? as : others.href ? "a" : "button";

let newProps = others;
let newProps = { ...others, ...actionMenu.getItemProps() };

const { onClick: originalOnClick } = newProps;

Expand All @@ -212,7 +210,7 @@ export const ActionsMenuItem = styled((props) => {
}

return <Component {...newProps} onClick={onClick} />;
}).attrs({ role: "listitem" })`
}).attrs({ role: "menuitem" })`
white-space: nowrap;
display: block;
width: 100%;
Expand Down Expand Up @@ -330,27 +328,30 @@ export const ActionsMenuBody = ({
<FloatingPortal
root={getFloatingUiRootElement(actionMenu.refs.reference)}
>
<FloatingFocusManager
context={actionMenu.context}
modal={actionMenu.modal}
>
<StyledActionsMenuContainer
ref={ref}
style={{
...actionMenu.floatingStyles,
zIndex: getFloatingUiZIndex(actionMenu.refs.reference)
}}
aria-labelledby={actionMenu.labelId}
{...actionMenu.getFloatingProps(props)}
className={`actionMenu-content ${
actionMenu.context.open ? "visible" : ""
}`}
{toggleState && (
<FloatingFocusManager
context={actionMenu.context}
modal={false}
guards={false}
>
<Menu menuWidth={menuWidth} isOpen={toggleState} role="list">
{children}
</Menu>
</StyledActionsMenuContainer>
</FloatingFocusManager>
<StyledActionsMenuContainer
ref={ref}
style={{
...actionMenu.floatingStyles,
zIndex: getFloatingUiZIndex(actionMenu.refs.reference)
}}
aria-labelledby={actionMenu.labelId}
{...actionMenu.getFloatingProps(props)}
className={`actionMenu-content ${
actionMenu.context.open ? "visible" : ""
}`}
>
<Menu menuWidth={menuWidth} isOpen={toggleState}>
{children}
</Menu>
</StyledActionsMenuContainer>
</FloatingFocusManager>
)}
</FloatingPortal>
</Wrapper>
</ActionMenuContext.Provider>
Expand Down
2 changes: 1 addition & 1 deletion lib/components/ActionsMenu/useActionMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function useActionMenu({
});
const dismiss = useDismiss(context);

const role = useRole(context);
const role = useRole(context, { role: "menu" });

const interactions = useInteractions([click, dismiss, role]);

Expand Down
77 changes: 37 additions & 40 deletions lib/components/Popover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,6 @@ const DIRECTIONS_MAP = {
bottomRight: "bottom-end"
};

const StyledPopoverContainer = styled.div`
pointer-events: none;
opacity: 0;
transition: all 300ms ease-in-out;
transition-delay: 300ms;
&.visible {
opacity: 1;
pointer-events: auto;
}
`;

const TooltipControl = styled.div`
border: none;
background: none;
Expand Down Expand Up @@ -81,7 +69,13 @@ const StyledPopover = styled.div`
box-shadow: ${themeGet("shadows.boxDefault")};
user-select: ${(props) => (props.enableSelectAll ? "all" : "auto")};
opacity: 1;
pointer-events: none;
opacity: 0;
&.visible {
opacity: 1;
pointer-events: auto;
}
& a {
font-size: ${themeGet("fontSizes.0")};
Expand Down Expand Up @@ -289,7 +283,11 @@ export default function Popover({
]
});

const hover = useHover(context, { move: false, handleClose: safePolygon() });
const hover = useHover(context, {
move: false,
handleClose: safePolygon(),
delay: { open: 400, close: 0 }
});
const focus = useFocus(context);
const dismiss = useDismiss(context);
const role = useRole(context, { role: "tooltip" });
Expand All @@ -303,7 +301,8 @@ export default function Popover({

const triggerProps = {
...getReferenceProps({
ref: refs.setReference
ref: refs.setReference,
"aria-describedby": context.floatingId
})
};

Expand Down Expand Up @@ -338,33 +337,31 @@ export default function Popover({
root={getFloatingUiRootElement(context.refs.reference)}
preserveTabOrder={true}
>
{text && (
<StyledPopoverContainer
className={`Tooltip popover ${visible ? "visible" : ""}`}
ref={refs.setFloating}
style={{
...floatingStyles,
zIndex: getFloatingUiZIndex(context.refs.reference)
}}
{...getFloatingProps()}
{text && visible && (
<FloatingFocusManager
initialFocus={context.refs?.reference}
context={context}
modal={false}
>
<FloatingFocusManager
initialFocus={context.refs?.reference}
context={context}
modal={false}
<StyledPopover
aria-hidden="false"
textAlign={textAlign}
width={width}
enableSelectAll={enableSelectAll}
className={`Tooltip popover ${
visible ? "visible" : ""
} ${directionClass}`}
ref={refs.setFloating}
style={{
...floatingStyles,
zIndex: getFloatingUiZIndex(context.refs.reference)
}}
{...getFloatingProps()}
ariaLabel={ariaLabel}
>
<StyledPopover
className={`${directionClass}`}
role="tooltip"
textAlign={textAlign}
width={width}
enableSelectAll={enableSelectAll}
ariaLabel={ariaLabel}
>
{text}
</StyledPopover>
</FloatingFocusManager>
</StyledPopoverContainer>
{text}
</StyledPopover>
</FloatingFocusManager>
)}
</FloatingPortal>
</Box>
Expand Down
4 changes: 2 additions & 2 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
@@ -1,6 +1,6 @@
{
"name": "orcs-design-system",
"version": "3.2.19",
"version": "3.2.20",
"engines": {
"node": "20.12.2"
},
Expand Down

0 comments on commit e60621b

Please sign in to comment.