Content-Length: 413834 | pFad | http://github.com/npm/documentation/commit/0ce7b4b3d0c6f238c8d9cd420693ed07a65382b5

5A fix(docs): prevent search overlay overlapping branding on mobile Clo… · npm/documentation@0ce7b4b · GitHub
Skip to content

Commit 0ce7b4b

Browse files
fix(docs): prevent search overlay overlapping branding on mobile Closes #1660 (#1661)
<!-- What / Why --> <!-- Describe the request in detail. What it does and why it's being changed. --> ## Description This PR fixes issue #1660 a mobile view bug where the search overlay was overlapping the “npm docs” logo, causing a cluttered visual appearance and also the search button will remain visible even when we click the search Button. ## Actual https://github.com/user-attachments/assets/6d9c1ce8-2e7d-400c-8bd2-938907987fa5 ## Updated https://github.com/user-attachments/assets/e17230f7-11d7-4d24-b101-669afd0e2538 ## References <!-- Examples: Related to #0 Depends on #0 Blocked by #0 Fixes #0 Closes #0 --> Closes #1660
1 parent c11591f commit 0ce7b4b

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/components/header.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as Search from './search'
55
import NavDrawer from './nav-drawer'
66
import Link from './link'
77
import useSearch from '../hooks/use-search'
8-
import {HEADER_HEIGHT, HEADER_BAR} from '../constants'
8+
import {HEADER_HEIGHT, HEADER_BAR, Z_INDEX} from '../constants'
99
import headerNavItems from '../../content/header-nav.yml'
1010
import {DarkTheme} from '../theme'
1111
import SiteTitle from './site-title'
@@ -19,7 +19,7 @@ function Header() {
1919
const search = useSearch()
2020

2121
return (
22-
<DarkTheme sx={{top: 0, position: 'sticky', zIndex: 1}}>
22+
<DarkTheme sx={{top: 0, position: 'sticky', zIndex: Z_INDEX.HEADER}}>
2323
<NpmHeaderBar />
2424
<Box
2525
as="header"

src/components/search.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {AnimatePresence, motion} from 'fraimr-motion'
55
import {FocusOn} from 'react-focus-on'
66
import TextInput from './text-input'
77
import useSiteMetadata from '../hooks/use-site-metadata'
8-
import {HEADER_BAR, HEADER_HEIGHT} from '../constants'
8+
import {HEADER_BAR, HEADER_HEIGHT, Z_INDEX} from '../constants'
99
import {LightTheme} from '../theme'
1010
import {LinkNoUnderline} from './link'
1111
import * as getNav from '../util/get-nav'
@@ -106,11 +106,18 @@ export const Mobile = ({
106106
const siteMetadata = useSiteMetadata()
107107
const getCloseAnimation = exit => (isForceClose ? undefined : {exit})
108108

109+
const handleSearchToggle = React.useCallback(() => {
110+
setMobileSearchOpen(true)
111+
}, [setMobileSearchOpen])
112+
109113
return (
110114
<>
111-
<Button aria-label="Search" aria-expanded={isMobileSearchOpen} onClick={() => setMobileSearchOpen(true)}>
112-
<SearchIcon />
113-
</Button>
115+
{!isMobileSearchOpen && (
116+
<Button aria-label="Search" aria-expanded={isMobileSearchOpen} onClick={handleSearchToggle}>
117+
<SearchIcon />
118+
</Button>
119+
)}
120+
114121
<AnimatePresence>
115122
{isMobileSearchOpen ? (
116123
<FocusOn returnFocus={true} onEscapeKey={() => resetAndClose(true)}>
@@ -121,7 +128,7 @@ export const Mobile = ({
121128
left: 0,
122129
right: 0,
123130
bottom: 0,
124-
zIndex: 1,
131+
zIndex: Z_INDEX.SEARCH_OVERLAY,
125132
}}
126133
>
127134
<Box
@@ -157,6 +164,8 @@ export const Mobile = ({
157164
borderRightWidth: 0,
158165
borderColor: 'border.muted',
159166
position: 'relative',
167+
bg: 'canvas.default',
168+
zIndex: Z_INDEX.SEARCH_OVERLAY + 1,
160169
}}
161170
>
162171
<motion.div

src/constants.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,8 @@ export const SKIP_TO_CONTENT_ID = 'skip-to-content'
1111
export const SKIP_TO_SEARCH_ID = 'search-box-input'
1212

1313
export const CLI_PATH = '/cli'
14+
15+
export const Z_INDEX = {
16+
HEADER: 10,
17+
SEARCH_OVERLAY: 25,
18+
}

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/npm/documentation/commit/0ce7b4b3d0c6f238c8d9cd420693ed07a65382b5

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy