Skip to content
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
2 changes: 2 additions & 0 deletions dist/render.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export default class Render {
private lastSelectedOption;
main: Main;
content: Content;
private scrollHandler;
private resizeHandler;
classes: CssClasses;
constructor(settings: Required<Settings>, classes: Required<CssClasses>, store: Store, callbacks: Callbacks);
enable(): void;
Expand Down
15 changes: 15 additions & 0 deletions dist/slimselect.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,13 @@ class Render {
this.ensureElementInView(this.content.list, selectedOption);
}
}
if (this.settings.contentPosition === 'fixed') {
this.moveContent();
this.scrollHandler = () => this.moveContent();
this.resizeHandler = () => this.moveContent();
window.addEventListener('scroll', this.scrollHandler, true);
window.addEventListener('resize', this.resizeHandler);
}
}
close() {
this.main.main.classList.remove(this.classes.openAbove);
Expand All @@ -414,6 +421,14 @@ class Render {
this.content.main.classList.remove(this.classes.openAbove);
this.content.main.classList.remove(this.classes.openBelow);
this.main.arrow.path.setAttribute('d', this.classes.arrowClose);
if (this.scrollHandler) {
window.removeEventListener('scroll', this.scrollHandler, true);
this.scrollHandler = undefined;
}
if (this.resizeHandler) {
window.removeEventListener('resize', this.resizeHandler);
this.resizeHandler = undefined;
}
}
updateClassStyles() {
this.main.main.className = '';
Expand Down
15 changes: 15 additions & 0 deletions dist/slimselect.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,13 @@ class Render {
this.ensureElementInView(this.content.list, selectedOption);
}
}
if (this.settings.contentPosition === 'fixed') {
this.moveContent();
this.scrollHandler = () => this.moveContent();
this.resizeHandler = () => this.moveContent();
window.addEventListener('scroll', this.scrollHandler, true);
window.addEventListener('resize', this.resizeHandler);
}
}
close() {
this.main.main.classList.remove(this.classes.openAbove);
Expand All @@ -412,6 +419,14 @@ class Render {
this.content.main.classList.remove(this.classes.openAbove);
this.content.main.classList.remove(this.classes.openBelow);
this.main.arrow.path.setAttribute('d', this.classes.arrowClose);
if (this.scrollHandler) {
window.removeEventListener('scroll', this.scrollHandler, true);
this.scrollHandler = undefined;
}
if (this.resizeHandler) {
window.removeEventListener('resize', this.resizeHandler);
this.resizeHandler = undefined;
}
}
updateClassStyles() {
this.main.main.className = '';
Expand Down
15 changes: 15 additions & 0 deletions dist/slimselect.global.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,13 @@ var SlimSelect = (function () {
this.ensureElementInView(this.content.list, selectedOption);
}
}
if (this.settings.contentPosition === 'fixed') {
this.moveContent();
this.scrollHandler = () => this.moveContent();
this.resizeHandler = () => this.moveContent();
window.addEventListener('scroll', this.scrollHandler, true);
window.addEventListener('resize', this.resizeHandler);
}
}
close() {
this.main.main.classList.remove(this.classes.openAbove);
Expand All @@ -415,6 +422,14 @@ var SlimSelect = (function () {
this.content.main.classList.remove(this.classes.openAbove);
this.content.main.classList.remove(this.classes.openBelow);
this.main.arrow.path.setAttribute('d', this.classes.arrowClose);
if (this.scrollHandler) {
window.removeEventListener('scroll', this.scrollHandler, true);
this.scrollHandler = undefined;
}
if (this.resizeHandler) {
window.removeEventListener('resize', this.resizeHandler);
this.resizeHandler = undefined;
}
}
updateClassStyles() {
this.main.main.className = '';
Expand Down
15 changes: 15 additions & 0 deletions dist/slimselect.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,13 @@
this.ensureElementInView(this.content.list, selectedOption);
}
}
if (this.settings.contentPosition === 'fixed') {
this.moveContent();
this.scrollHandler = () => this.moveContent();
this.resizeHandler = () => this.moveContent();
window.addEventListener('scroll', this.scrollHandler, true);
window.addEventListener('resize', this.resizeHandler);
}
}
close() {
this.main.main.classList.remove(this.classes.openAbove);
Expand All @@ -418,6 +425,14 @@
this.content.main.classList.remove(this.classes.openAbove);
this.content.main.classList.remove(this.classes.openBelow);
this.main.arrow.path.setAttribute('d', this.classes.arrowClose);
if (this.scrollHandler) {
window.removeEventListener('scroll', this.scrollHandler, true);
this.scrollHandler = undefined;
}
if (this.resizeHandler) {
window.removeEventListener('resize', this.resizeHandler);
this.resizeHandler = undefined;
}
}
updateClassStyles() {
this.main.main.className = '';
Expand Down
2 changes: 1 addition & 1 deletion dist/slimselect.min.js

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions dist/slimselect.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,13 @@
this.ensureElementInView(this.content.list, selectedOption);
}
}
if (this.settings.contentPosition === 'fixed') {
this.moveContent();
this.scrollHandler = () => this.moveContent();
this.resizeHandler = () => this.moveContent();
window.addEventListener('scroll', this.scrollHandler, true);
window.addEventListener('resize', this.resizeHandler);
}
}
close() {
this.main.main.classList.remove(this.classes.openAbove);
Expand All @@ -418,6 +425,14 @@
this.content.main.classList.remove(this.classes.openAbove);
this.content.main.classList.remove(this.classes.openBelow);
this.main.arrow.path.setAttribute('d', this.classes.arrowClose);
if (this.scrollHandler) {
window.removeEventListener('scroll', this.scrollHandler, true);
this.scrollHandler = undefined;
}
if (this.resizeHandler) {
window.removeEventListener('resize', this.resizeHandler);
this.resizeHandler = undefined;
}
}
updateClassStyles() {
this.main.main.className = '';
Expand Down
2 changes: 1 addition & 1 deletion dist/slimselect.umd.min.js

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions docs/assets/index.js

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions src/slim-select/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export default class Render {
public main: Main
public content: Content

private scrollHandler: (() => void) | undefined;
private resizeHandler: (() => void) | undefined;

// Classes
public classes: CssClasses

Expand Down Expand Up @@ -123,6 +126,16 @@ export default class Render {
this.ensureElementInView(this.content.list, selectedOption)
}
}
if (this.settings.contentPosition === 'fixed') {
this.moveContent();

// Instant (non-debounced) handlers
this.scrollHandler = () => this.moveContent();
this.resizeHandler = () => this.moveContent();

window.addEventListener('scroll', this.scrollHandler, true); // capture phase
window.addEventListener('resize', this.resizeHandler);
}
}

public close(): void {
Expand All @@ -132,6 +145,16 @@ export default class Render {
this.content.main.classList.remove(this.classes.openAbove)
this.content.main.classList.remove(this.classes.openBelow)
this.main.arrow.path.setAttribute('d', this.classes.arrowClose)

if (this.scrollHandler) {
window.removeEventListener('scroll', this.scrollHandler, true);
this.scrollHandler = undefined;
}

if (this.resizeHandler) {
window.removeEventListener('resize', this.resizeHandler);
this.resizeHandler = undefined;
}
}

public updateClassStyles(): void {
Expand Down