Skip to content

Commit

Permalink
Merge pull request #581 from shibaobun/master
Browse files Browse the repository at this point in the history
Add `fixed` contentPosition option
  • Loading branch information
brianvoe authored Nov 21, 2024
2 parents e49388c + 4ec48c9 commit 9ff6db9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/slim-select/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export default class Render {

// Misc classes
// Add content position class
if (this.settings.contentPosition === 'relative') {
if (this.settings.contentPosition === 'relative' || this.settings.contentPosition === 'fixed') {
this.content.main.classList.add('ss-' + this.settings.contentPosition)
}
}
Expand Down Expand Up @@ -1355,8 +1355,10 @@ export default class Render {
// Set the content position
const containerRect = this.main.main.getBoundingClientRect()
this.content.main.style.margin = '-' + (mainHeight + contentHeight - 1) + 'px 0px 0px 0px'
this.content.main.style.top = containerRect.top + containerRect.height + window.scrollY + 'px'
this.content.main.style.left = containerRect.left + window.scrollX + 'px'
this.content.main.style.top =
containerRect.top + containerRect.height + (this.settings.contentPosition === 'fixed' ? 0 : window.scrollY) + 'px'
this.content.main.style.left =
containerRect.left + (this.settings.contentPosition === 'fixed' ? 0 : window.scrollX) + 'px'
this.content.main.style.width = containerRect.width + 'px'
}

Expand All @@ -1372,8 +1374,13 @@ export default class Render {
this.content.main.style.margin = '-1px 0px 0px 0px'
// Dont do anything if the content is relative
if (this.settings.contentPosition !== 'relative') {
this.content.main.style.top = containerRect.top + containerRect.height + window.scrollY + 'px'
this.content.main.style.left = containerRect.left + window.scrollX + 'px'
this.content.main.style.top =
containerRect.top +
containerRect.height +
(this.settings.contentPosition === 'fixed' ? 0 : window.scrollY) +
'px'
this.content.main.style.left =
containerRect.left + (this.settings.contentPosition === 'fixed' ? 0 : window.scrollX) + 'px'
this.content.main.style.width = containerRect.width + 'px'
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/slim-select/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class Settings {
public searchHighlight: boolean
public closeOnSelect: boolean
public contentLocation: HTMLElement | null
public contentPosition: 'relative' | 'absolute'
public contentPosition: 'relative' | 'absolute' | 'fixed'
public openPosition: 'auto' | 'up' | 'down'
public placeholderText: string
public allowDeselect: boolean
Expand Down
4 changes: 4 additions & 0 deletions src/slim-select/slimselect.scss
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@
height: 100%;
}

&.ss-fixed {
position: fixed;
}

&.ss-open-above {
flex-direction: column-reverse;
opacity: 1;
Expand Down

0 comments on commit 9ff6db9

Please sign in to comment.