Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

chore(core): clear the fixable Bottom Sheet lint suppressions (#5155)

Xinzi Zhoue508afce7f74
diff --git a/.changeset/bottom-sheet-lint-suppressions.md b/.changeset/bottom-sheet-lint-suppressions.md
new file mode 100644
index 0000000000..d30690208c
--- /dev/null
+++ b/.changeset/bottom-sheet-lint-suppressions.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[chore] Clear the mechanically fixable ESLint suppressions from the Bottom Sheet promotion: `BottomSheet` and `BottomSheetSwitcher` now use the React 19 context APIs (`<Context>` as provider, `use()`), the panel drops its duplicate body-element ref in favor of the one the gesture hook already tracks, and `useSheetGestures` reads `prefers-reduced-motion` through the shared `useMediaQuery` subscription so an open sheet follows a preference change.
+
+@imdreamrunner
diff --git a/packages/core/src/BottomSheet/BottomSheet.tsx b/packages/core/src/BottomSheet/BottomSheet.tsx
index b42df381c7..f1e16fb845 100644
--- a/packages/core/src/BottomSheet/BottomSheet.tsx
+++ b/packages/core/src/BottomSheet/BottomSheet.tsx
@@ -25,8 +25,8 @@
*/
import {
+ use,
useCallback,
- useContext,
useEffect,
useLayoutEffect,
useRef,
@@ -493,10 +493,9 @@ function SwitcherBottomSheetItem({
{/* A switcher item consumes its parent controller. Its content starts a
fresh ownership scope so a nested BottomSheet is standalone unless
it establishes a nested BottomSheetSwitcher of its own. */}
- {/* eslint-disable-next-line @eslint-react/no-context-provider -- preserve the promoted Lab implementation */}
- <BottomSheetSwitcherContext.Provider value={null}>
+ <BottomSheetSwitcherContext value={null}>
{children}
- </BottomSheetSwitcherContext.Provider>
+ </BottomSheetSwitcherContext>
</BottomSheetPanel>
</div>
);
@@ -507,8 +506,7 @@ function SwitcherBottomSheetItem({
* BottomSheetSwitcher shared dialog when given a sheetId inside that context.
*/
export function BottomSheet(props: BottomSheetProps) {
- // eslint-disable-next-line @eslint-react/no-use-context -- preserve the promoted Lab implementation
- const switcher = useContext(BottomSheetSwitcherContext);
+ const switcher = use(BottomSheetSwitcherContext);
const runtimeSheetId = (props as {sheetId?: string}).sheetId;
const hasValidSheetId =
typeof runtimeSheetId === 'string' && runtimeSheetId.length > 0;
diff --git a/packages/core/src/BottomSheet/BottomSheetPanel.tsx b/packages/core/src/BottomSheet/BottomSheetPanel.tsx
index 6cb04f51e4..f53b60492f 100644
--- a/packages/core/src/BottomSheet/BottomSheetPanel.tsx
+++ b/packages/core/src/BottomSheet/BottomSheetPanel.tsx
@@ -301,7 +301,6 @@ export function BottomSheetPanel({
...props
}: BottomSheetPanelProps) {
const elementRef = useRef<HTMLDivElement | null>(null);
- const bodyElementRef = useRef<HTMLDivElement | null>(null);
const previousStateRef = useRef(state);
const reactivatedEntranceRef = useRef(false);
const onMotionStartRef = useRef(onMotionStart);
@@ -336,6 +335,7 @@ export function BottomSheetPanel({
contentProps,
handleProps,
bodyProps,
+ bodyElementRef,
sheetRef,
dragOffset,
settledOffset,
@@ -362,14 +362,6 @@ export function BottomSheetPanel({
},
[onElementChange, sheetRef],
);
- const setBodyElement = useCallback(
- (element: HTMLDivElement | null) => {
- bodyProps.ref(element);
- bodyElementRef.current = element;
- },
- // eslint-disable-next-line @eslint-react/exhaustive-deps -- preserve the promoted Lab implementation
- [bodyProps.ref],
- );
useMobileKeyboard({
bodyRef: bodyElementRef,
bottomClearance: MOBILE_KEYBOARD_BOTTOM_CLEARANCE,
@@ -535,8 +527,7 @@ export function BottomSheetPanel({
? {style: {paddingBlockEnd: `${scrollPreservationInset}px`}}
: {},
)}
- {...bodyProps}
- ref={setBodyElement}>
+ {...bodyProps}>
{children}
</div>
</div>
diff --git a/packages/core/src/BottomSheet/BottomSheetSwitcher.tsx b/packages/core/src/BottomSheet/BottomSheetSwitcher.tsx
index 7e22ed032c..b3cefa68da 100644
--- a/packages/core/src/BottomSheet/BottomSheetSwitcher.tsx
+++ b/packages/core/src/BottomSheet/BottomSheetSwitcher.tsx
@@ -50,11 +50,7 @@ import {
useFocusTrap,
useScrollLock,
} from '../hooks';
-import {
- composeEventHandlers,
- mergeProps,
- mergeRefs,
-} from '../utils';
+import {composeEventHandlers, mergeProps, mergeRefs} from '../utils';
import {
BottomSheetSwitcherContext,
type BottomSheetSwitcherContextValue,
@@ -610,8 +606,7 @@ export function BottomSheetSwitcher({
(props['aria-labelledby'] == null ? activeLabel : undefined);
return (
- // eslint-disable-next-line @eslint-react/no-context-provider -- preserve the promoted Lab implementation
- <BottomSheetSwitcherContext.Provider value={contextValue}>
+ <BottomSheetSwitcherContext value={contextValue}>
<dialog
{...props}
{...dialogPresentationProps}
@@ -626,7 +621,7 @@ export function BottomSheetSwitcher({
: undefined)}>
{children}
</dialog>
- </BottomSheetSwitcherContext.Provider>
+ </BottomSheetSwitcherContext>
);
}
diff --git a/packages/core/src/BottomSheet/useMobileKeyboard.ts b/packages/core/src/BottomSheet/useMobileKeyboard.ts
index dfc9800d81..8eb070bfcb 100644
--- a/packages/core/src/BottomSheet/useMobileKeyboard.ts
+++ b/packages/core/src/BottomSheet/useMobileKeyboard.ts
@@ -32,7 +32,7 @@ const NON_TEXT_INPUT_TYPES = new Set([
]);
interface UseMobileKeyboardOptions {
- bodyRef: RefObject<HTMLDivElement | null>;
+ bodyRef: RefObject<HTMLElement | null>;
bottomClearance: number;
isEnabled: boolean;
isFullyExpanded: boolean;
diff --git a/packages/core/src/BottomSheet/useSheetGestures.ts b/packages/core/src/BottomSheet/useSheetGestures.ts
index dda51a7fb4..5dc65322f5 100644
--- a/packages/core/src/BottomSheet/useSheetGestures.ts
+++ b/packages/core/src/BottomSheet/useSheetGestures.ts
@@ -4,7 +4,8 @@
/**
* @file useSheetGestures.ts
- * @input Uses React (useCallback, useEffect, useMemo, useRef, useState)
+ * @input Uses React (useCallback, useEffect, useMemo, useRef, useState) and
+ * the core useMediaQuery hook
* @output Exports useSheetGestures hook and its option/result types
* @position Internal to BottomSheet; not exported from the core entry point
*
@@ -43,8 +44,10 @@ import {
type CSSProperties,
type MouseEvent as ReactMouseEvent,
type PointerEvent as ReactPointerEvent,
+ type RefObject,
type UIEvent as ReactUIEvent,
} from 'react';
+import {useMediaQuery} from '../hooks';
import {
computeDetentOffsets,
isPeekOffset,
@@ -210,6 +213,13 @@ export interface UseSheetGesturesResult {
* scrolling); normal scrolling passes through untouched.
*/
bodyProps: SheetBodyProps;
+ /**
+ * The body element `bodyProps.ref` is attached to. The hook tracks the node
+ * anyway (it owns the non-passive touch listeners on it), so a host that
+ * also needs the element reads it here rather than wrapping `bodyProps.ref`
+ * in a second callback ref.
+ */
+ bodyElementRef: RefObject<HTMLElement | null>;
/** Current live drag translate in px (0 = fully expanded, larger = collapsed). */
dragOffset: number;
/** Translate of the resting detent in px (0 = tallest detent). */
@@ -1066,8 +1076,10 @@ export function useSheetGestures({
}
}, []);
- // eslint-disable-next-line @eslint-react/exhaustive-deps -- re-read the preference whenever the sheet opens
- const reducedMotion = useMemo(() => prefersReducedMotion(), [isOpen]);
+ // Subscribed, not memoized: the preference can change while a sheet is open,
+ // and this branch decides whether the settle runs as a transition at all.
+ // The imperative gesture paths read prefersReducedMotion() directly.
+ const reducedMotion = useMediaQuery('(prefers-reduced-motion: reduce)');
const reconcileScrollPreservationInset = useCallback(
(body: HTMLElement) => {
@@ -1165,6 +1177,7 @@ export function useSheetGestures({
contentProps,
handleProps,
bodyProps,
+ bodyElementRef: bodyNodeRef,
dragOffset,
settledOffset,
isDragging,