Skip to content

Commit 40992f5

Browse files
authored
Merge pull request NotionX#380 from NotionX/hide-search-event
added onHideSearch event
2 parents 667e8ed + 4305a94 commit 40992f5

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

packages/react-notion-x/src/components/header.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ export const Search: React.FC<{
8787
search?: SearchNotionFn
8888
title?: React.ReactNode
8989
}> = ({ block, search, title = 'Search' }) => {
90-
const { searchNotion, rootPageId, isShowingSearch } = useNotionContext()
90+
const { searchNotion, rootPageId, isShowingSearch, onHideSearch } =
91+
useNotionContext()
9192
const onSearchNotion = search || searchNotion
9293

9394
const [isSearchOpen, setIsSearchOpen] = React.useState(isShowingSearch)
@@ -101,6 +102,9 @@ export const Search: React.FC<{
101102

102103
const onCloseSearch = React.useCallback(() => {
103104
setIsSearchOpen(false)
105+
if (onHideSearch) {
106+
onHideSearch()
107+
}
104108
}, [])
105109

106110
useHotkeys('cmd+p', (event) => {

packages/react-notion-x/src/context.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface NotionContext {
2121
mapImageUrl: MapImageUrlFn
2222
searchNotion?: SearchNotionFn
2323
isShowingSearch?: boolean
24+
onHideSearch?: () => void
2425

2526
rootPageId?: string
2627
rootDomain?: string
@@ -49,6 +50,7 @@ export interface PartialNotionContext {
4950
mapImageUrl?: MapImageUrlFn
5051
searchNotion?: SearchNotionFn
5152
isShowingSearch?: boolean
53+
onHideSearch?: () => void
5254

5355
rootPageId?: string
5456
rootDomain?: string
@@ -151,6 +153,7 @@ const defaultNotionContext: NotionContext = {
151153
mapImageUrl: defaultMapImageUrl,
152154
searchNotion: null,
153155
isShowingSearch: false,
156+
onHideSearch: null,
154157

155158
fullPage: false,
156159
darkMode: false,

packages/react-notion-x/src/renderer.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const NotionRenderer: React.FC<{
1919
mapImageUrl?: MapImageUrlFn
2020
searchNotion?: SearchNotionFn
2121
isShowingSearch?: boolean
22+
onHideSearch?: () => void
2223

2324
rootPageId?: string
2425
rootDomain?: string
@@ -62,6 +63,7 @@ export const NotionRenderer: React.FC<{
6263
mapImageUrl,
6364
searchNotion,
6465
isShowingSearch,
66+
onHideSearch,
6567
fullPage,
6668
rootPageId,
6769
rootDomain,
@@ -97,6 +99,7 @@ export const NotionRenderer: React.FC<{
9799
mapImageUrl={mapImageUrl}
98100
searchNotion={searchNotion}
99101
isShowingSearch={isShowingSearch}
102+
onHideSearch={onHideSearch}
100103
fullPage={fullPage}
101104
rootPageId={rootPageId}
102105
rootDomain={rootDomain}

0 commit comments

Comments
 (0)