Skip to content

Commit bac9718

Browse files
committed
Update version to 3.0.16 in package.json and enhance AccordionContent component for better accessibility on web.
1 parent e07b3c5 commit bac9718

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

packages/gluestack-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@gluestack-ui/core",
33
"description": "Universal UI components for React Native, Expo, and Next.js",
4-
"version": "3.0.15",
4+
"version": "3.0.16",
55
"main": "./lib/esm/index.js",
66
"module": "./lib/esm/index.js",
77
"types": "./lib/esm/index.d.ts",

packages/gluestack-core/src/accordion/creator/AccordionContent.tsx

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,44 @@
1-
import React, { forwardRef, useContext } from 'react';
1+
import React, {
2+
forwardRef,
3+
useContext,
4+
useLayoutEffect,
5+
useRef,
6+
} from 'react';
7+
import { mergeRefs } from '@gluestack-ui/utils/common';
8+
import { Platform } from 'react-native';
29
import { AccordionItemContext } from './Context';
310
import AnimatedHeight from './AnimatedHeight';
411

512
export const AccordionContent = (StyledAccordionContent: any) =>
613
forwardRef(({ children, ...props }: any, ref?: any) => {
714
const { regionProps, isExpanded } = useContext(AccordionItemContext);
15+
const contentRef = useRef<HTMLElement | null>(null);
16+
const mergedRef = mergeRefs([ref, contentRef]);
17+
18+
// On web, collapsed panel content stays mounted (e.g. for height animation) but must
19+
// not be tab-focusable. RN Web's View does not forward `inert`, so set it on the host.
20+
useLayoutEffect(() => {
21+
if (Platform.OS !== 'web') return;
22+
const node = contentRef.current;
23+
if (!node || typeof node.setAttribute !== 'function') return;
24+
if (!isExpanded) {
25+
node.setAttribute('inert', '');
26+
} else {
27+
node.removeAttribute('inert');
28+
}
29+
}, [isExpanded]);
30+
31+
const webCollapsedA11y =
32+
Platform.OS === 'web' && !isExpanded ? { 'aria-hidden': true } : {};
833

934
return (
1035
<AnimatedHeight hide={!isExpanded}>
11-
<StyledAccordionContent ref={ref} {...props} {...regionProps}>
36+
<StyledAccordionContent
37+
ref={mergedRef}
38+
{...props}
39+
{...regionProps}
40+
{...webCollapsedA11y}
41+
>
1242
{children}
1343
</StyledAccordionContent>
1444
</AnimatedHeight>

0 commit comments

Comments
 (0)