Skip to content

Commit

Permalink
Merge pull request #115 from bilelz/search-automatic_scroll_114
Browse files Browse the repository at this point in the history
✨feat(search): scroll on focus #114
  • Loading branch information
fcamblor authored May 2, 2021
2 parents 964091c + 606e889 commit 1d30376
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 14 deletions.
24 changes: 17 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
"vite": "2.1.5"
},
"dependencies": {
"@types/smoothscroll-polyfill": "0.3.1",
"bootstrap": "5.0.0-beta3",
"leaflet": "1.7.1",
"leaflet.markercluster": "1.4.1",
"lit-element": "2.4.0",
"page": "1.11.6"
"page": "1.11.6",
"smoothscroll-polyfill": "0.4.4"
}
}
}
1 change: 0 additions & 1 deletion public/autocomplete-cache/aux.json

This file was deleted.

1 change: 0 additions & 1 deletion public/autocomplete-cache/con.json

This file was deleted.

3 changes: 1 addition & 2 deletions src/components/vmd-commune-selector.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {Strings} from "../utils/Strings";
import {TemplateResult} from "lit-html";
import {DirectiveFn} from "lit-html/lib/directive";


export type AutocompleteTriggered = { value: string };
export type CommuneSelected = { commune: Commune };
export type DepartementSelected = { departement: Departement };
Expand Down Expand Up @@ -179,7 +178,7 @@ export class VmdCommuneSelectorComponent extends LitElement {
return html`
<div class="autocomplete ${classMap({'_open': this.showDropdown, '_withButton': this.filter || !this.inputModeFixedToText })}">
<input type="text" class="autocomplete-input"
@focusin="${() => { this.inputHasFocus = true; }}"
@focusin="${() => { this.inputHasFocus = true; window.scroll({ top: this.offsetTop - 32, behavior: 'smooth' }); }}"
@focusout="${this.hideDropdownWhenInputHasNotFocus}"
@keyup="${this.valueChanged}" .value="${this.filter}"
inputmode="${this.inputMode}" placeholder="${this.inputModeFixedToText?'Commune, Code postal, Département...':this.inputMode==='numeric'?'Saisissez un code postal':'Saisissez un nom de commune'}"
Expand Down
4 changes: 3 additions & 1 deletion src/routing/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,15 @@ class Routing {
Promise.resolve(slottedViewComponentFactoryResult)),
titlePromise(context.params).catch(() => Routing.DEFAULT_TITLE)
]).then(([slottedViewTemplateFactory, title]) => {
this.currentPath === '/' && window.scroll({ top: 0, behavior: 'smooth' })

this.currentPath = path;
this.currentTemplateResultCreator = slottedViewTemplateFactory;

document.title = title;

this._viewChangeCallbacks.forEach(callback => callback(slottedViewTemplateFactory, path));

Analytics.INSTANCE.navigationSurNouvellePage(pageName);
})
});
Expand Down
3 changes: 3 additions & 0 deletions src/vmd-app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {LitElement, html, customElement, property, css, unsafeCSS} from 'lit-ele
import {Router, SlottedTemplateResultFactory} from "./routing/Router";
import globalCss from './styles/global.scss'
import {TemplateResult} from "lit-html";
import smoothscroll from 'smoothscroll-polyfill';

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

constructor() {
super();

smoothscroll.polyfill();

Router.installRoutes((viewTemplateResult, path) => {
this.viewTemplateResult = viewTemplateResult;
Expand Down

0 comments on commit 1d30376

Please sign in to comment.