Skip to content

Commit c6635bd

Browse files
committed
add selection, collapsedSelection and option slots
1 parent 7ae1b99 commit c6635bd

File tree

2 files changed

+14
-27
lines changed

2 files changed

+14
-27
lines changed

src/lib/Svelecte.svelte

+13-8
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@
274274
$: itemRenderer = typeof renderer === 'function'
275275
? renderer
276276
: (formatterList[renderer] || formatterList.default.bind({ label: currentLabelField}));
277-
$: collapseSelectionFn = collapseSelection ? settings.collapseSelectionFn.bind(i18n_actual) : null;
278277
279278
/** ************************************ dropdown-specific */
280279
@@ -1156,8 +1155,9 @@
11561155
{#if selectedOptions.length }
11571156
<!-- TODO: re-implement comments -->
11581157
{#if multiple && doCollapse}
1159-
<span>{@html collapseSelectionFn(selectedOptions.length, selectedOptions) }</span>
1158+
<slot name="collapsedSelection" {selectedOptions} i18n={i18n_actual}>{i18n_actual.collapsedSelection(selectedOptions.length)}</slot>
11601159
{:else}
1160+
<slot name="selection" {selectedOptions} {bindItem}>
11611161
{#each selectedOptions as opt (opt[currentValueField])}
11621162
<div class="sv-item--container" animate:flip={{duration: flipDurationMs }}>
11631163
<div class="sv-item--wrap" class:is-multi={multiple}>
@@ -1175,6 +1175,7 @@
11751175
{/if}
11761176
</div>
11771177
{/each}
1178+
</slot>
11781179
{/if}
11791180
{/if}
11801181
@@ -1262,9 +1263,11 @@
12621263
class="sv-item--wrap in-dropdown"
12631264
class:sv-dd-item-active={dropdown_index === index}
12641265
>
1265-
<div class="sv-item--content">
1266-
{@html highlightSearch(opt, false, input_value, itemRenderer, disableHighlight) }
1267-
</div>
1266+
<slot name="option" item={opt}>
1267+
<div class="sv-item--content">
1268+
{@html highlightSearch(opt, false, input_value, itemRenderer, disableHighlight) }
1269+
</div>
1270+
</slot>
12681271
</div>
12691272
{/if}
12701273
</div>
@@ -1278,9 +1281,11 @@
12781281
class="sv-item--wrap in-dropdown"
12791282
class:sv-dd-item-active={dropdown_index === i}
12801283
>
1281-
<div class="sv-item--content">
1282-
{@html highlightSearch(opt, false, input_value, itemRenderer, disableHighlight) }
1283-
</div>
1284+
<slot name="option" item={opt}>
1285+
<div class="sv-item--content">
1286+
{@html highlightSearch(opt, false, input_value, itemRenderer, disableHighlight) }
1287+
</div>
1288+
</slot>
12841289
</div>
12851290
{/if}
12861291
{/each}

src/lib/settings.js

+1-19
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@
2929
* @callback i18n_aria_inputFocus
3030
* @returns {string}
3131
*
32-
* @callback i18n_collapseSelectionFn
33-
* @param {number} selectionCount
34-
* @param {object[]} selection
35-
* @this {I18nObject}
36-
* @returns {string}
37-
*
3832
* @typedef {object} I18nObject
3933
* @property {string} empty
4034
* @property {string} nomatch
@@ -87,7 +81,6 @@
8781
* @property {number|null} vlItemSize
8882
* @property {number|null} vlHeight
8983
* @property {I18nObject} i18n
90-
* @property {i18n_collapseSelectionFn} collapseSelectionFn
9184
*/
9285
const /**@type {Settings} */ settings = {
9386
// html
@@ -147,18 +140,7 @@ const /**@type {Settings} */ settings = {
147140
fetchEmpty: 'No data related to your search',
148141
collapsedSelection: count => `${count} selected`,
149142
createRowLabel: value => `Create '${value}'`
150-
},
151-
/**
152-
* Bound to 'i18n'
153-
*
154-
* @this {I18nObject}
155-
* @param {number} selectionCount
156-
* @param {object[]} selection
157-
* @returns {string}
158-
*/
159-
collapseSelectionFn: function(selectionCount, selection) {
160-
return this.collapsedSelection(selectionCount);
161-
},
143+
}
162144
}
163145

164146
export default settings;

0 commit comments

Comments
 (0)