Skip to content

Commit 9a160d6

Browse files
committed
Fix initial focus preview out of focus if selection is below preview
Add auto focus (scrollIntoView) if user selects the item below editor preview pane
1 parent 02b0858 commit 9a160d6

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/components/molecules/SearchModalNoteResultItem.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,27 @@ const SearchModalNoteResultItem = ({
7575
[highlightMatchedTerm]
7676
)
7777

78+
const updateSelectedItemAndFocus = useCallback(
79+
(target, note, id) => {
80+
{
81+
updateSelectedItem(note, id)
82+
83+
setTimeout(() => {
84+
target.scrollIntoView(
85+
{
86+
// todo: [komediruzecki-12/12/2020] Smooth looks nice, do we want instant (as now) or slowly auto scrolling to element
87+
behavior: 'auto',
88+
block: 'nearest',
89+
inline: 'nearest',
90+
},
91+
20
92+
)
93+
})
94+
}
95+
},
96+
[updateSelectedItem]
97+
)
98+
7899
return (
79100
<Container>
80101
<MetaContainer onClick={navigate}>
@@ -106,7 +127,9 @@ const SearchModalNoteResultItem = ({
106127
selectedItemId == result.id ? 'search-result-selected' : ''
107128
}
108129
key={getSearchResultKey(note._id, result.id)}
109-
onClick={() => updateSelectedItem(note, result.id)}
130+
onClick={(event: MouseEvent) =>
131+
updateSelectedItemAndFocus(event.target, note, result.id)
132+
}
110133
onDoubleClick={() =>
111134
navigateToEditorFocused(
112135
note._id,

0 commit comments

Comments
 (0)