Skip to content

Commit 1d30376

Browse files
authored
Merge pull request #115 from bilelz/search-automatic_scroll_114
✨feat(search): scroll on focus #114
2 parents 964091c + 606e889 commit 1d30376

File tree

7 files changed

+28
-14
lines changed

7 files changed

+28
-14
lines changed

package-lock.json

+17-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
"vite": "2.1.5"
2626
},
2727
"dependencies": {
28+
"@types/smoothscroll-polyfill": "0.3.1",
2829
"bootstrap": "5.0.0-beta3",
2930
"leaflet": "1.7.1",
3031
"leaflet.markercluster": "1.4.1",
3132
"lit-element": "2.4.0",
32-
"page": "1.11.6"
33+
"page": "1.11.6",
34+
"smoothscroll-polyfill": "0.4.4"
3335
}
34-
}
36+
}

public/autocomplete-cache/aux.json

-1
This file was deleted.

public/autocomplete-cache/con.json

-1
This file was deleted.

src/components/vmd-commune-selector.component.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {Strings} from "../utils/Strings";
1616
import {TemplateResult} from "lit-html";
1717
import {DirectiveFn} from "lit-html/lib/directive";
1818

19-
2019
export type AutocompleteTriggered = { value: string };
2120
export type CommuneSelected = { commune: Commune };
2221
export type DepartementSelected = { departement: Departement };
@@ -179,7 +178,7 @@ export class VmdCommuneSelectorComponent extends LitElement {
179178
return html`
180179
<div class="autocomplete ${classMap({'_open': this.showDropdown, '_withButton': this.filter || !this.inputModeFixedToText })}">
181180
<input type="text" class="autocomplete-input"
182-
@focusin="${() => { this.inputHasFocus = true; }}"
181+
@focusin="${() => { this.inputHasFocus = true; window.scroll({ top: this.offsetTop - 32, behavior: 'smooth' }); }}"
183182
@focusout="${this.hideDropdownWhenInputHasNotFocus}"
184183
@keyup="${this.valueChanged}" .value="${this.filter}"
185184
inputmode="${this.inputMode}" placeholder="${this.inputModeFixedToText?'Commune, Code postal, Département...':this.inputMode==='numeric'?'Saisissez un code postal':'Saisissez un nom de commune'}"

src/routing/Router.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,15 @@ class Routing {
108108
Promise.resolve(slottedViewComponentFactoryResult)),
109109
titlePromise(context.params).catch(() => Routing.DEFAULT_TITLE)
110110
]).then(([slottedViewTemplateFactory, title]) => {
111+
this.currentPath === '/' && window.scroll({ top: 0, behavior: 'smooth' })
112+
111113
this.currentPath = path;
112114
this.currentTemplateResultCreator = slottedViewTemplateFactory;
113115

114116
document.title = title;
115117

116118
this._viewChangeCallbacks.forEach(callback => callback(slottedViewTemplateFactory, path));
117-
119+
118120
Analytics.INSTANCE.navigationSurNouvellePage(pageName);
119121
})
120122
});

src/vmd-app.component.ts

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {LitElement, html, customElement, property, css, unsafeCSS} from 'lit-ele
22
import {Router, SlottedTemplateResultFactory} from "./routing/Router";
33
import globalCss from './styles/global.scss'
44
import {TemplateResult} from "lit-html";
5+
import smoothscroll from 'smoothscroll-polyfill';
56

67
@customElement('vmd-app')
78
export class VmdAppComponent extends LitElement {
@@ -21,6 +22,8 @@ export class VmdAppComponent extends LitElement {
2122

2223
constructor() {
2324
super();
25+
26+
smoothscroll.polyfill();
2427

2528
Router.installRoutes((viewTemplateResult, path) => {
2629
this.viewTemplateResult = viewTemplateResult;

0 commit comments

Comments
 (0)