diff --git a/.gitignore b/.gitignore index 8c2a1ce0..7bbb37c4 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ dist # test coverage reports coverage +text-results/ diff --git a/package.json b/package.json index 575feda3..ac5341dc 100644 --- a/package.json +++ b/package.json @@ -48,14 +48,17 @@ "rehype-slug": "^6.0.0", "svelte-check": "^4.0.5", "svelte-multiselect": "^10.3.0", + "svelte-popperjs": "^1.3.2", "svelte-preprocess": "^6.0.3", "svelte-toc": "^0.5.9", - "svelte-zoo": "^0.4.13", + "svelte-zoo": "^0.4.12", "svelte2tsx": "^0.7.22", "typescript": "5.6.3", "typescript-eslint": "^8.11.0", "vite": "^5.4.9", - "vitest": "^2.1.3" + "vitest": "^2.1.3", + "tippy": "^0.0.0", + "tippy.js": "^6.2.5" }, "keywords": [ "svelte", diff --git a/readme.md b/readme.md index 84802297..ec8530b1 100644 --- a/readme.md +++ b/readme.md @@ -423,6 +423,11 @@ Full list of props/bindable variables for this component. The `Option` type you If `maxSelect={1}`, `value` will be the single item in `selected` (or `null` if `selected` is empty). If `maxSelect != 1`, `maxSelect` and `selected` are equal. Warning: Setting `value` does not rendered state on initial mount, meaning `bind:value` will update local variable `value` whenever internal component state changes but passing a `value` when component first mounts won't be reflected in UI. This is because the source of truth for rendering is `bind:selected`. `selected` is reactive to `value` internally but only on reassignment from initial value. Suggestions for better solutions than [#249](https://github.com/janosh/svelte-multiselect/issues/249) welcome! +1. ```ts + fixed: boolean | null = false + ``` + if fixed is set, will cause the dropdown to be rendered with popper.js fixed strategy, enabling the dropdown to expand outside it's parent. This is good for modals / scrollable containers. + ## 🎰   Slots `MultiSelect.svelte` accepts the following named slots: diff --git a/src/lib/MultiSelect.svelte b/src/lib/MultiSelect.svelte index 582eb2fb..368d1d60 100644 --- a/src/lib/MultiSelect.svelte +++ b/src/lib/MultiSelect.svelte @@ -1,11 +1,13 @@ + + +# Fixed Position +Often times you want the dropdown to escape a modal or a parent that forces the dropdown to scroll inside of it. + +svelte-popper.js is used to position the dropdown. By default it is in absolute mode, but by specifying the fixed prop it sets popper.js to fixed mode, enabling the dropdown to expand outside of it's parent. + +Below is an example where fixed position is useful, a div that has a fixed height and scroll. + +```css + +``` + + + + +## Without fixed + +
+ +```svelte example stackblitz id="without-fixed" + + +
+ + +
+ + +``` + +## With fixed + +the fixed prop enables the dropdown to be positioned fixed, and + +
+ +```svelte example stackblitz id="with-fixed" + + +
+ + +
+ + +```