Skip to content

Commit 4a8b992

Browse files
fix: support inert in React 18 matrix (#566)
1 parent ac46184 commit 4a8b992

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

.changeset/smart-walls-peel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudflare/kumo": patch
3+
---
4+
5+
Restore React 18-compatible Sidebar inert attribute handling while keeping the full React compatibility CI suite.

packages/kumo/src/components/sidebar/sidebar.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ export interface SidebarContextValue {
148148

149149
const SidebarContext = createContext<SidebarContextValue | null>(null);
150150

151+
const reactMajorVersion = parseInt(React.version, 10);
152+
153+
function inertValue(value: boolean): boolean | undefined {
154+
if (reactMajorVersion >= 19) {
155+
return value;
156+
}
157+
158+
// React <19 does not emit unknown boolean attributes like `inert={true}`.
159+
return (value ? "true" : undefined) as boolean | undefined;
160+
}
161+
151162
/**
152163
* Hook to access sidebar state and actions from any descendant component.
153164
*
@@ -1736,7 +1747,7 @@ const SidebarCollapsibleContent = forwardRef<
17361747
id={contentId}
17371748
role="region"
17381749
aria-hidden={!isOpen}
1739-
inert={!isOpen ? ("true" as unknown as boolean) : undefined}
1750+
inert={inertValue(!isOpen)}
17401751
data-open={isOpen || undefined}
17411752
className={cn(
17421753
"grid",
@@ -1886,7 +1897,7 @@ const SidebarSlidingView = forwardRef<HTMLDivElement, SidebarSlidingViewProps>(
18861897
data-sidebar="sliding-view"
18871898
data-value={value}
18881899
aria-hidden={!isActive}
1889-
inert={!isActive ? ("true" as unknown as boolean) : undefined}
1900+
inert={inertValue(!isActive)}
18901901
className={cn(
18911902
"flex w-full shrink-0 flex-col min-h-0",
18921903
!isActive && "pointer-events-none",

0 commit comments

Comments
 (0)