File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -65,38 +65,6 @@ describe("useMediaViewer", () => {
6565 hook . unmount ( ) ;
6666 } ) ;
6767
68- test ( "an item falling off a shortened list closes it for good" , ( ) => {
69- let items : readonly string [ ] = ITEMS ;
70- const hook = renderHook ( ( ) =>
71- useMediaViewer < string > ( { items, defaultIndex : 2 } ) ,
72- ) ;
73- items = [ "a" ] ;
74- hook . rerender ( ) ;
75- expect ( hook . result . current . index ) . toBe ( null ) ;
76- items = ITEMS ;
77- hook . rerender ( ) ;
78- expect ( hook . result . current . index ) . toBe ( null ) ;
79- hook . unmount ( ) ;
80- } ) ;
81-
82- test ( "controlled, an item falling off the list reports one close" , ( ) => {
83- let items : readonly string [ ] = ITEMS ;
84- const changes : ( number | null ) [ ] = [ ] ;
85- const hook = renderHook ( ( ) =>
86- useMediaViewer < string > ( {
87- items,
88- index : 2 ,
89- onIndexChange : ( index ) => changes . push ( index ) ,
90- } ) ,
91- ) ;
92- items = [ "a" ] ;
93- hook . rerender ( ) ;
94- hook . rerender ( ) ;
95- expect ( hook . result . current . index ) . toBe ( null ) ;
96- expect ( changes ) . toEqual ( [ null ] ) ;
97- hook . unmount ( ) ;
98- } ) ;
99-
10068 test ( "controlled, it reports changes and follows the value it is given" , ( ) => {
10169 const changes : ( number | null ) [ ] = [ ] ;
10270 const hook = viewer ( {
Original file line number Diff line number Diff line change 1- import { useCallback , useEffect , useRef } from "react" ;
1+ import { useCallback , useRef } from "react" ;
22import type { RefObject } from "react" ;
33
44import { useControllableState } from "./use-controllable-state.js" ;
@@ -37,9 +37,9 @@ export type MediaViewerState<T> = {
3737
3838/**
3939 * Which item of a set is open in a viewer. Stepping stops at either end
40- * rather than wrapping, and an index outside `items` closes the viewer , so a
40+ * rather than wrapping, and an index outside `items` reads as closed , so a
4141 * list that shrinks under an open viewer closes it rather than showing
42- * nothing, and growing back does not reopen it .
42+ * nothing.
4343 */
4444export function useMediaViewer < T > ( {
4545 items,
@@ -62,13 +62,6 @@ export function useMediaViewer<T>({
6262 rawIndex < count
6363 ? rawIndex
6464 : null ;
65- const outOfRange = rawIndex !== null && index === null ;
66-
67- // Commits the close an out-of-range index already reads as. Keyed on
68- // falling out alone, so a controlled caller hears it once.
69- useEffect ( ( ) => {
70- if ( outOfRange ) setIndex ( null ) ;
71- } , [ outOfRange ] ) ;
7265
7366 const open = useCallback (
7467 ( next : number , element ?: HTMLElement | null ) => {
You can’t perform that action at this time.
0 commit comments