import cx from 'classnames' import type { NextPage } from 'next' import { useRef, useState } from 'react' import scrollIntoView from 'smooth-scroll-into-view-if-needed' import Button from '../../docs/fixtures/Button' import CloseExample from '../../docs/fixtures/CloseExample' import Code from '../../docs/fixtures/Code' import Container from '../../docs/fixtures/Container' import ScrollUp from '../../docs/fixtures/ScrollUp' import SheetContent from '../../docs/fixtures/SheetContent' import SnapMarker from '../../docs/fixtures/SnapMarker' import { scrollable } from '../../docs/headings' import MetaTags from '../../docs/MetaTags' import { BottomSheet, BottomSheetRef } from '../../src' import type { GetStaticProps } from '../_app' export { getStaticProps } from '../_app' const rand = (_) => _[~~(Math.random() * _.length)] const colors = [ 'bg-gray-50', 'bg-gray-100', 'bg-gray-200', 'bg-gray-300', 'bg-gray-400', 'bg-gray-500', 'bg-gray-600', 'bg-gray-700', 'bg-gray-800', 'bg-gray-900', ] const widths = [ 'w-1/2', 'w-2/5', 'w-3/5', 'w-1/3', 'w-2/3', 'w-1/4', 'w-3/4', 'w-1/5', 'w-4/5', 'w-1/6', 'w-5/6', 'w-full', ] const rows = Array.from(Array(20), (_, x) => ({ key: x, bg: rand(colors), w: rand(widths), })) const ScrollableFixturePage: NextPage = ({ description, homepage, meta, name, }) => { const [expandOnContentDrag, setExpandOnContentDrag] = useState(true) const focusRef = useRef() const sheetRef = useRef() return ( <> } ref={sheetRef} initialFocusRef={focusRef} defaultSnap={({ maxHeight }) => maxHeight / 2} snapPoints={({ maxHeight }) => [ maxHeight - maxHeight / 10, maxHeight / 4, maxHeight * 0.6, ]} expandOnContentDrag={expandOnContentDrag} >

The sheet will always try to set initial focus on the first interactive element it finds.

If none is found it sets keyboard focus to the container.

You can override this with initialFocusRef.

{rows.map(({ key, bg, w }) => (
))} { await scrollIntoView(focusRef.current, { block: 'end' }) focusRef.current.focus() }} /> ) } export default ScrollableFixturePage