Skip to content

Commit

Permalink
LPS-201300 Fixing Accessibility conflict between ClayPanelGroup and C…
Browse files Browse the repository at this point in the history
…layPanel
  • Loading branch information
AkramYoussoufi committed Nov 14, 2023
1 parent c851f49 commit 59f8e81
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/clay-panel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"build": "cross-env NODE_ENV=production babel src --root-mode upward --out-dir lib --extensions .ts,.tsx",
"buildTypes": "cross-env NODE_ENV=production tsc --project ./tsconfig.declarations.json",
"prepublishOnly": "yarn build && yarn buildTypes",
"test": "jest --config ../../jest.config.js"
"test": "jest --config ../../jest.config.js --updateSnapshot"
},
"keywords": [
"clay",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ exports[`ClayPanel renders with multiple panels 1`] = `
>
<div
class="panel"
role="tablist"
role="none"
>
<div
class="panel-header"
Expand All @@ -162,7 +162,7 @@ exports[`ClayPanel renders with multiple panels 1`] = `
</div>
<div
class="panel"
role="tablist"
role="none"
>
<div
class="panel-header"
Expand All @@ -181,7 +181,7 @@ exports[`ClayPanel renders with multiple panels 1`] = `
</div>
<div
class="panel"
role="tablist"
role="none"
>
<button
aria-expanded="false"
Expand Down
35 changes: 34 additions & 1 deletion packages/clay-panel/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import ClayPanelGroup from './Group';
import ClayPanelHeader from './Header';
import ClayPanelTitle from './Title';

import {useRef, useEffect, useState} from 'react';

Check failure on line 24 in packages/clay-panel/src/index.tsx

View workflow job for this annotation

GitHub Actions / test

modules must be imported only once (duplicate import: "react")

Check failure on line 24 in packages/clay-panel/src/index.tsx

View workflow job for this annotation

GitHub Actions / test

destructured names in imports must be sorted

export interface IProps extends React.HTMLAttributes<HTMLDivElement> {
/**
* Flag to indicate that Panel is collapsable.
Expand Down Expand Up @@ -107,13 +109,44 @@ function ClayPanel({

const {prefersReducedMotion} = useProvider();

//Setting reference to the clayComponent

Check failure on line 112 in packages/clay-panel/src/index.tsx

View workflow job for this annotation

GitHub Actions / test

Expected space or tab after '//' in comment
const clayPanelReference = useRef<HTMLDivElement | null>(null);

//Setting an init role for the clayComponent

Check failure on line 115 in packages/clay-panel/src/index.tsx

View workflow job for this annotation

GitHub Actions / test

Expected space or tab after '//' in comment
const [roleValue, setRoleValue] = useState('tablist');

//Function that checks for the parent Role if they have tablist this is made to check if the user used GroupComponent to render multiple panels.

Check failure on line 118 in packages/clay-panel/src/index.tsx

View workflow job for this annotation

GitHub Actions / test

Expected space or tab after '//' in comment
const checkRoleParent = () => {
const clayPanelElement = clayPanelReference.current;

if (
clayPanelElement &&
clayPanelElement.parentNode &&
(clayPanelElement.parentNode as HTMLDivElement).getAttribute(
'role'
) === 'tablist'
) {
setRoleValue('none');
} else {
setRoleValue('tablist');
}

return roleValue;
};

useEffect(() => {
// Execute the check when the component is mounted
checkRoleParent();
}, []);

return (
<div
{...otherProps}
className={classNames('panel', className, {
[`panel-${displayType}`]: displayType,
})}
role="tablist"
ref={clayPanelReference}
role={roleValue}
>
{!collapsable && (
<>
Expand Down

0 comments on commit 59f8e81

Please sign in to comment.