Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

fix(city input): use react autocomplete instead of SearchableSelect which does not work on safari #144

Merged
merged 3 commits into from
Apr 12, 2022
Merged
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"pg": "^8.7.3",
"pg-hstore": "^2.3.4",
"react": "^18.0.0",
"react-autocomplete": "^1.8.1",
"react-dom": "^18.0.0",
"react-leaflet": "^3.2.5",
"sanitize-html": "^2.7.0",
Expand Down
8 changes: 0 additions & 8 deletions public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ h1 .fr-text--lead {
height: 100%;
}

.select-search-options {
z-index: 1100 !important;
}

.leaflet-popup-close-button {
box-shadow: none !important;
}
Expand All @@ -77,7 +73,3 @@ h1 .fr-text--lead {
width: auto;
margin: auto;
}

.select-search-input input {
margin-top: 0.5rem;
}
55 changes: 39 additions & 16 deletions src/components/Directory/SearchBar.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import {
Alert,
Button,
Col,
Row,
SearchableSelect,
Select,
} from "@dataesr/react-dsfr";
import { Alert, Button, Col, Row, Select } from "@dataesr/react-dsfr";
import React, { Dispatch, SetStateAction, useEffect, useState } from "react";
import ReactAutocomplete from "react-autocomplete";

import {
AROUND_ME,
Expand Down Expand Up @@ -101,14 +95,43 @@ const SearchBar = ({
return (
<Row className="fr-pb-2w" alignItems="middle">
<Col n="md-9 12">
<SearchableSelect
selected={positionFilter}
onChange={setPositionFilter}
onTextChange={setFilterText}
filter={() => true}
label="Rechercher par ville ou code postal"
options={options}
/>
<div className="fr-select-group">
<label className="fr-label fr-mb-2v" htmlFor="city-search">
Rechercher par ville ou code postal
</label>
<div className="select-search-input">
<ReactAutocomplete
id="city-search"
inputProps={{ className: "fr-select" }}
wrapperStyle={{}}
getItemValue={(item) => item.label}
items={options}
renderItem={(item, isHighlighted) => (
<li
role="option"
key={item.label}
aria-selected={isHighlighted}
className={`select-search-option ${
isHighlighted ? "select-search-option__selected" : ""
}`}
>
{item.label}
</li>
)}
renderMenu={(items) => (
<ul className="select-search-options midlength-input select-search-options__visible no-bullet fr-p-0">
{items}
</ul>
)}
value={filterText}
onChange={(e) => setFilterText(e.target.value)}
onSelect={(val) => {
setFilterText(val);
setPositionFilter(val);
}}
/>
</div>
</div>
<SubSearch>
<Select
selected={otherFilters[FILTER.PUBLIC]}
Expand Down
8 changes: 4 additions & 4 deletions src/services/frontend/geo.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ const searchCommunes = (
const communes = response.data
.sort((a, b) => b.population - a.population)
.map((commune) => ({
label: `${commune.nom}, ${commune.departement?.nom}`,
value: commune.centre.coordinates,
label:
commune.nom +
(commune.departement ? `, ${commune.departement.nom}` : ""),
value: commune.centre?.coordinates,
}));
action(communes.concat(AROUND_ME_OPTION));
});
Expand Down Expand Up @@ -82,7 +84,6 @@ const searchDepartments = async (
)
)
);

const communes = results
.flatMap((result) => result.data)
.flatMap((commune) =>
Expand Down Expand Up @@ -114,7 +115,6 @@ const searchDepartments = async (

return Promise.resolve();
};

export const search = async (
filter: string,
action: React.Dispatch<
Expand Down
15 changes: 14 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3005,6 +3005,11 @@ doctrine@^3.0.0:
dependencies:
esutils "^2.0.2"

dom-scroll-into-view@1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/dom-scroll-into-view/-/dom-scroll-into-view-1.0.1.tgz#32abb92f0d8feca6215162aef43e4b449ab8d99c"
integrity sha1-Mqu5Lw2P7KYhUWKu9D5LRJq42Zw=

dom-serializer@^1.0.1:
version "1.3.2"
resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-1.3.2.tgz#6206437d32ceefaec7161803230c7a20bc1b4d91"
Expand Down Expand Up @@ -6554,7 +6559,7 @@ prompts@^2.0.1, prompts@^2.4.2:
kleur "^3.0.3"
sisteransi "^1.0.5"

prop-types@^15.7.2:
prop-types@^15.5.10, prop-types@^15.7.2:
version "15.8.1"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5"
integrity sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==
Expand Down Expand Up @@ -6675,6 +6680,14 @@ raw-body@2.4.1:
iconv-lite "0.4.24"
unpipe "1.0.0"

react-autocomplete@^1.8.1:
version "1.8.1"
resolved "https://registry.yarnpkg.com/react-autocomplete/-/react-autocomplete-1.8.1.tgz#ebbbc400006aa91ad538b2d14727b9e7e5d06310"
integrity sha1-67vEAABqqRrVOLLRRye55+XQYxA=
dependencies:
dom-scroll-into-view "1.0.1"
prop-types "^15.5.10"

react-dom@^18.0.0:
version "18.0.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.0.0.tgz#26b88534f8f1dbb80853e1eabe752f24100d8023"
Expand Down