Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SearchBox: Fix broken flyTo on mobile #574

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/components/SearchBox/onHighlightFactory.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AutocompleteHighlightChangeReason } from '@mui/material';
import { Feature } from '../../services/types';
import { GeocoderOption, Option } from './types';

Expand Down Expand Up @@ -31,7 +32,9 @@ export const getSkeleton = ({ geocoder }: GeocoderOption): Feature => {
};

export const onHighlightFactory =
(setPreview: (feature: unknown) => void) => (_: never, option: Option) => {
(setPreview: (feature: unknown) => void) =>
(_: never, option: Option, reason: AutocompleteHighlightChangeReason) => {
if (reason === 'touch') return;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain what was the issue here? I know it sometimes needed a double click, though I don't understand why this should help. (Though it helps! 🎉 😃 )

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first click on the option runs the highlight callback. The second clicks then ran the actual click listener.
Actually I also don't fully understand why instantly returning fixes this issue 😅 but it does and now we just return when the click was from a touch device.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.. on click is like a hover on mobile. That makes sense! THX

instantly returning fixes the issue

That almost looks like some mobile magic.. 😅 aka "if callback takes shorter than something, lets skip it .. apple is known for that 🙃

if (!option) return;
if (option.type === 'star' && option.star.center) {
const { center } = option.star;
Expand Down
Loading