({
placeholder,
onOpen,
value = '',
onChange,
onSubmit,
onFocus,
overModal = false,
}: ShellFieldProps)
| 33 | .join(', '); |
| 34 | |
| 35 | export function ShellField({ |
| 36 | placeholder, |
| 37 | onOpen, |
| 38 | value = '', |
| 39 | onChange, |
| 40 | onSubmit, |
| 41 | onFocus, |
| 42 | overModal = false, |
| 43 | }: ShellFieldProps): ReactElement | null { |
| 44 | const isPhone = useIsPhone(); |
| 45 | // Sideways the bar stays compact, so the field stands on its compact top. |
| 46 | const barHeight = useIsPhoneLandscape() ? cluster.compact : cluster.rest; |
| 47 | const router = useRouter(); |
| 48 | // Settings and forms have no bar; the field rests in the bar's place. |
| 49 | const hasBar = |
| 50 | !overModal && !hidesCluster(router?.pathname ?? '', router?.asPath); |
| 51 | const { p } = useShellScroll(); |
| 52 | const [isFocused, setIsFocused] = useState(false); |
| 53 | const inputRef = useRef<HTMLInputElement>(null); |
| 54 | // undefined until the anchor has looked for its modal's overlay; null when |
| 55 | // there is none, and the field falls back to the root. |
| 56 | const [modalOverlay, setModalOverlay] = useState<Element | null>(); |
| 57 | const anchorRef = useCallback((node: HTMLSpanElement | null) => { |
| 58 | if (node) { |
| 59 | setModalOverlay(node.closest('.ReactModal__Overlay')); |
| 60 | } |
| 61 | }, []); |
| 62 | const viewport = useVisualViewport(isFocused); |
| 63 | // The app footer owns the bottom while it is up. |
| 64 | const { title: appFooterTitle } = useMobileAppFooterContext(); |
| 65 | const hasAppFooter = !!appFooterTitle; |
| 66 | const isShown = isPhone && !hasAppFooter; |
| 67 | useRegisterShellField(isShown); |
| 68 | |
| 69 | useEffect(() => { |
| 70 | setShellFieldFocused(isFocused); |
| 71 | return () => setShellFieldFocused(false); |
| 72 | }, [isFocused]); |
| 73 | |
| 74 | if (!isShown) { |
| 75 | return null; |
| 76 | } |
| 77 | |
| 78 | // iOS lays the keyboard over the page instead of resizing it, so the |
| 79 | // visual viewport is the only place that knows how tall the keyboard is. |
| 80 | const keyboard = isFocused |
| 81 | ? Math.max( |
| 82 | 0, |
| 83 | window.innerHeight - (viewport.height ?? 0) - (viewport.offsetTop ?? 0), |
| 84 | ) |
| 85 | : 0; |
| 86 | const progress = isFocused ? 0 : p; |
| 87 | const restBottom = `calc(${cluster.floor} + ${ |
| 88 | hasBar ? barHeight + field.gap : 0 |
| 89 | }px)`; |
| 90 | const focusedBottom = |
| 91 | keyboard > 0 |
| 92 | ? `${keyboard + field.gap}px` |
nothing calls this directly
no test coverage detected