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 9b5b89e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 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: 33 additions & 2 deletions packages/clay-panel/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
useControlledState,
} from '@clayui/shared';
import classNames from 'classnames';
import React from 'react';
import React, {useEffect, useRef, useState} from 'react';
import {CSSTransition} from 'react-transition-group';

import ClayPanelBody from './Body';
Expand Down Expand Up @@ -107,13 +107,44 @@ function ClayPanel({

const {prefersReducedMotion} = useProvider();

// Setting reference to the clayComponent
const clayPanelReference = useRef<HTMLDivElement | null>(null);

// Setting an init role for the clayComponent
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.
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 9b5b89e

Please sign in to comment.