Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions plugins/search/src/events/formHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ export const createFormHandlers = ({
}

if (newSuggestions.length) {
if (appState.interfaceType === 'keyboard') {
viewportRef.current?.focus()
}
viewportRef.current?.focus()
if (appState.breakpoint === 'mobile') {
dispatch({ type: 'TOGGLE_EXPANDED', payload: false })
services.eventBus.emit('search:close')
Expand Down
4 changes: 2 additions & 2 deletions plugins/search/src/events/formHandlers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('createFormHandlers', () => {
expect(updateMap).not.toHaveBeenCalled()
})

test('handleSubmit fetches suggestions and updates map (keyboard)', async () => {
test('handleSubmit fetches suggestions and updates map', async () => {
fetchSuggestions.mockResolvedValueOnce({
sanitisedValue: 'rome',
results: [
Expand All @@ -132,7 +132,7 @@ describe('createFormHandlers', () => {

await handlers.handleSubmit(
{ preventDefault: jest.fn() },
{ interfaceType: 'keyboard' },
{},
{
suggestions: [],
selectedIndex: -1,
Expand Down
3 changes: 2 additions & 1 deletion plugins/search/src/events/suggestionHandlers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { updateMap } from '../utils/updateMap.js'

export const createSuggestionHandlers = ({ dispatch, services, mapProvider, markers, showMarker, markerOptions }) => {
export const createSuggestionHandlers = ({ dispatch, services, mapProvider, markers, showMarker, markerOptions, viewportRef }) => {
const selectionMessage = (suggestions, index) =>
index >= 0
? `${suggestions[index]?.text}. ${index + 1} of ${suggestions.length} is highlighted`
Expand All @@ -17,6 +17,7 @@ export const createSuggestionHandlers = ({ dispatch, services, mapProvider, mark
services.eventBus.emit('search:close')
}

viewportRef.current?.focus()
updateMap({ mapProvider, bounds: suggestion.bounds, point: suggestion.point, markers, showMarker, markerOptions })
services.eventBus.emit('search:match', { query: suggestion.text, ...suggestion })
},
Expand Down
8 changes: 7 additions & 1 deletion plugins/search/src/events/suggestionHandlers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jest.mock('../utils/updateMap.js')
describe('createSuggestionHandlers', () => {
let dispatch
let services
let viewportRef
let handlers

beforeEach(() => {
Expand All @@ -19,13 +20,16 @@ describe('createSuggestionHandlers', () => {
announce: jest.fn()
}

viewportRef = { current: { focus: jest.fn() } }

handlers = createSuggestionHandlers({
dispatch,
services,
mapProvider: 'map',
markers: 'markers',
showMarker: true,
markerOptions: { backgroundColor: 'blue' }
markerOptions: { backgroundColor: 'blue' },
viewportRef
})

jest.clearAllMocks()
Expand All @@ -41,6 +45,7 @@ describe('createSuggestionHandlers', () => {
expect(dispatch).toHaveBeenCalledWith({ type: 'SET_VALUE', payload: 'Paris' })
expect(dispatch).toHaveBeenCalledWith({ type: 'HIDE_SUGGESTIONS' })
expect(dispatch).toHaveBeenCalledWith({ type: 'SET_SELECTED', payload: -1 })
expect(viewportRef.current.focus).toHaveBeenCalled()
expect(updateMap).toHaveBeenCalledWith(expect.objectContaining({ bounds: 'b', point: 'p' }))
expect(services.eventBus.emit).toHaveBeenCalledWith(
'search:match',
Expand All @@ -55,6 +60,7 @@ describe('createSuggestionHandlers', () => {

expect(dispatch).toHaveBeenCalledWith({ type: 'TOGGLE_EXPANDED', payload: false })
expect(services.eventBus.emit).toHaveBeenCalledWith('search:close')
expect(viewportRef.current.focus).toHaveBeenCalled()
})

// ---------- ArrowDown ----------
Expand Down
Loading