Skip to content

Commit

Permalink
TPP 849 fix tabable children on floatin UI with aria hidden (#316)
Browse files Browse the repository at this point in the history
* fixed issues wiht accessability

* 3.2.22
  • Loading branch information
KitoC authored Aug 8, 2024
1 parent 0522fc9 commit 1302b46
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
11 changes: 9 additions & 2 deletions lib/components/ActionsMenu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,13 @@ export const ActionsMenuItem = styled((props) => {

const { as, ...others } = props;
const Component = as ? as : others.href ? "a" : "button";
const disabled = !actionMenu?.context?.open ?? false;

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

const { onClick: originalOnClick } = newProps;

Expand All @@ -205,7 +210,8 @@ export const ActionsMenuItem = styled((props) => {
newProps = {
...others,
type: "button",
["data-action-menu-id"]: id
["data-action-menu-id"]: id,
disabled
};
}

Expand Down Expand Up @@ -323,6 +329,7 @@ export const ActionsMenuBody = ({
);

const visible = actionMenu.context.open;

const ActionMenuContent = (
<StyledActionsMenuContainer
ref={ref}
Expand Down
23 changes: 22 additions & 1 deletion lib/components/Popover/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { cloneElement, useState } from "react";
import React, { cloneElement, useEffect, useState } from "react";
import {
useFloating,
autoUpdate,
Expand Down Expand Up @@ -336,6 +336,27 @@ export default function Popover({
? direction
: context.placement;

useEffect(() => {
// Following code disables the tabbing of elements for popovers when it is not open.
const floatingEl = context?.refs?.floating?.current;

if (!floatingEl) return;

const childrenAnchors = Array.from(floatingEl.getElementsByTagName?.("a"));

if (!childrenAnchors.length) return;

if (visible) {
childrenAnchors.forEach((anchor) => {
anchor.tabIndex = "";
});
} else {
childrenAnchors.forEach((anchor) => {
anchor.tabIndex = "-1";
});
}
}, [visible, context]);

const Popover = (
<StyledPopover
textAlign={textAlign}
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.21",
"version": "3.2.22",
"engines": {
"node": "20.12.2"
},
Expand Down

0 comments on commit 1302b46

Please sign in to comment.