Skip to content

Commit 72dfd99

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 72dfd99

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/components/molecules/SearchModalNoteResultItem.tsx

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

78+
const updateSelectedItemAndFocus = useCallback(
79+
(target, note, id) => {
80+
{
81+
updateSelectedItem(note, id)
82+
83+
setTimeout(() => {
84+
if (target) {
85+
target.scrollIntoView(
86+
{
87+
// todo: [komediruzecki-12/12/2020] Smooth looks nice,
88+
// do we want instant (as now) or slowly auto scrolling to element?
89+
behavior: 'auto',
90+
block: 'nearest',
91+
inline: 'nearest',
92+
},
93+
20
94+
)
95+
}
96+
})
97+
}
98+
},
99+
[updateSelectedItem]
100+
)
101+
78102
return (
79103
<Container>
80104
<MetaContainer onClick={navigate}>
@@ -106,7 +130,9 @@ const SearchModalNoteResultItem = ({
106130
selectedItemId == result.id ? 'search-result-selected' : ''
107131
}
108132
key={getSearchResultKey(note._id, result.id)}
109-
onClick={() => updateSelectedItem(note, result.id)}
133+
onClick={(event: MouseEvent) =>
134+
updateSelectedItemAndFocus(event.target, note, result.id)
135+
}
110136
onDoubleClick={() =>
111137
navigateToEditorFocused(
112138
note._id,

0 commit comments

Comments
 (0)