carbon-components-svelte 0.91.0 → 0.92.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/ComboBox/ComboBox.svelte +48 -7
- package/src/ComposedModal/ComposedModal.svelte +1 -0
- package/src/Dropdown/Dropdown.svelte +7 -7
- package/src/Modal/Modal.svelte +1 -0
- package/src/MultiSelect/MultiSelect.svelte +5 -5
- package/src/NumberInput/NumberInput.svelte +5 -5
- package/types/ComboBox/ComboBox.svelte.d.ts +10 -3
- package/types/Dropdown/Dropdown.svelte.d.ts +1 -1
- package/types/MultiSelect/MultiSelect.svelte.d.ts +3 -3
- package/types/NumberInput/NumberInput.svelte.d.ts +2 -2
package/package.json
CHANGED
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
export let disabled = false;
|
|
53
53
|
|
|
54
54
|
/** Specify the title text of the combobox */
|
|
55
|
-
export let
|
|
55
|
+
export let labelText = "";
|
|
56
56
|
|
|
57
57
|
/** Set to `true` to visually hide the label text */
|
|
58
58
|
export let hideLabel = false;
|
|
@@ -95,8 +95,12 @@
|
|
|
95
95
|
*/
|
|
96
96
|
export let clearFilterOnOpen = false;
|
|
97
97
|
|
|
98
|
+
/** Set to `true` to enable autocomplete with typeahead */
|
|
99
|
+
export let typeahead = false;
|
|
100
|
+
|
|
98
101
|
/**
|
|
99
|
-
* Determine if an item should be filtered given the current combobox value
|
|
102
|
+
* Determine if an item should be filtered given the current combobox value.
|
|
103
|
+
* Will be ignored if `typeahead` is enabled.
|
|
100
104
|
* @type {(item: Item, value: string) => boolean}
|
|
101
105
|
*/
|
|
102
106
|
export let shouldFilterItem = () => true;
|
|
@@ -149,6 +153,25 @@
|
|
|
149
153
|
let prevSelectedId = null;
|
|
150
154
|
let highlightedIndex = -1;
|
|
151
155
|
let valueBeforeOpen = "";
|
|
156
|
+
let prevInputLength = 0;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* @param {Item} item
|
|
160
|
+
* @param {string} inputValue
|
|
161
|
+
* @returns {boolean}
|
|
162
|
+
*/
|
|
163
|
+
function autocompleteCustomFilter(item, inputValue) {
|
|
164
|
+
if (inputValue.length === 0) {
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const lowercaseItem = item.text.toLowerCase();
|
|
169
|
+
const lowercaseInput = inputValue.toLowerCase();
|
|
170
|
+
|
|
171
|
+
return lowercaseItem.startsWith(lowercaseInput);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
$: filterFn = typeahead ? autocompleteCustomFilter : shouldFilterItem;
|
|
152
175
|
|
|
153
176
|
function change(dir) {
|
|
154
177
|
let index = highlightedIndex + dir;
|
|
@@ -201,7 +224,7 @@
|
|
|
201
224
|
value = "";
|
|
202
225
|
}
|
|
203
226
|
|
|
204
|
-
filteredItems = items.filter((item) =>
|
|
227
|
+
filteredItems = items.filter((item) => filterFn(item, value));
|
|
205
228
|
} else {
|
|
206
229
|
highlightedIndex = -1;
|
|
207
230
|
filteredItems = [];
|
|
@@ -251,7 +274,25 @@
|
|
|
251
274
|
$: menuId = `menu-${id}`;
|
|
252
275
|
$: comboId = `combo-${id}`;
|
|
253
276
|
$: highlightedId = items[highlightedIndex] ? items[highlightedIndex].id : 0;
|
|
254
|
-
$: filteredItems = items.filter((item) =>
|
|
277
|
+
$: filteredItems = items.filter((item) => filterFn(item, value));
|
|
278
|
+
|
|
279
|
+
$: if (typeahead) {
|
|
280
|
+
const showNewSuggestion =
|
|
281
|
+
value.length > prevInputLength && filteredItems.length > 0;
|
|
282
|
+
|
|
283
|
+
prevInputLength = value.length;
|
|
284
|
+
|
|
285
|
+
if (ref && showNewSuggestion) {
|
|
286
|
+
const suggestion = itemToString(filteredItems[0]).slice(value.length);
|
|
287
|
+
const selectionStart = value.length;
|
|
288
|
+
const selectionEnd = selectionStart + suggestion.length;
|
|
289
|
+
|
|
290
|
+
tick().then(() => {
|
|
291
|
+
ref.value = value + suggestion;
|
|
292
|
+
ref.setSelectionRange(selectionStart, selectionEnd);
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
}
|
|
255
296
|
</script>
|
|
256
297
|
|
|
257
298
|
<svelte:window
|
|
@@ -263,15 +304,15 @@
|
|
|
263
304
|
/>
|
|
264
305
|
|
|
265
306
|
<div class:bx--list-box__wrapper={true}>
|
|
266
|
-
{#if
|
|
307
|
+
{#if labelText || $$slots.labelText}
|
|
267
308
|
<label
|
|
268
309
|
for={id}
|
|
269
310
|
class:bx--label={true}
|
|
270
311
|
class:bx--label--disabled={disabled}
|
|
271
312
|
class:bx--visually-hidden={hideLabel}
|
|
272
313
|
>
|
|
273
|
-
<slot name="
|
|
274
|
-
{
|
|
314
|
+
<slot name="labelText">
|
|
315
|
+
{labelText}
|
|
275
316
|
</slot>
|
|
276
317
|
</label>
|
|
277
318
|
{/if}
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
export let disabled = false;
|
|
62
62
|
|
|
63
63
|
/** Specify the title text */
|
|
64
|
-
export let
|
|
64
|
+
export let labelText = "";
|
|
65
65
|
|
|
66
66
|
/** Set to `true` to indicate an invalid state */
|
|
67
67
|
export let invalid = false;
|
|
@@ -177,14 +177,14 @@
|
|
|
177
177
|
class:bx--dropdown__wrapper--inline--invalid={inline && invalid}
|
|
178
178
|
{...$$restProps}
|
|
179
179
|
>
|
|
180
|
-
{#if
|
|
180
|
+
{#if labelText}
|
|
181
181
|
<label
|
|
182
182
|
for={id}
|
|
183
183
|
class:bx--label={true}
|
|
184
184
|
class:bx--label--disabled={disabled}
|
|
185
185
|
class:bx--visually-hidden={hideLabel}
|
|
186
186
|
>
|
|
187
|
-
{
|
|
187
|
+
{labelText}
|
|
188
188
|
</label>
|
|
189
189
|
{/if}
|
|
190
190
|
<ListBox
|
|
@@ -193,10 +193,10 @@
|
|
|
193
193
|
{size}
|
|
194
194
|
{name}
|
|
195
195
|
aria-label={$$props["aria-label"]}
|
|
196
|
-
class="bx--dropdown
|
|
197
|
-
{direction === 'top' && 'bx--list-box--up'}
|
|
198
|
-
{invalid && 'bx--dropdown--invalid'}
|
|
199
|
-
{!invalid && warn && 'bx--dropdown--warning'}
|
|
196
|
+
class="bx--dropdown
|
|
197
|
+
{direction === 'top' && 'bx--list-box--up'}
|
|
198
|
+
{invalid && 'bx--dropdown--invalid'}
|
|
199
|
+
{!invalid && warn && 'bx--dropdown--warning'}
|
|
200
200
|
{open && 'bx--dropdown--open'}
|
|
201
201
|
{size === 'sm' && 'bx--dropdown--sm'}
|
|
202
202
|
{size === 'xl' && 'bx--dropdown--xl'}
|
package/src/Modal/Modal.svelte
CHANGED
|
@@ -117,8 +117,8 @@
|
|
|
117
117
|
*/
|
|
118
118
|
export let translateWithIdSelection = undefined;
|
|
119
119
|
|
|
120
|
-
/** Specify the
|
|
121
|
-
export let
|
|
120
|
+
/** Specify the label text */
|
|
121
|
+
export let labelText = "";
|
|
122
122
|
|
|
123
123
|
/** Set to `true` to pass the item to `itemToString` in the checkbox */
|
|
124
124
|
export let useTitleInItem = false;
|
|
@@ -325,15 +325,15 @@
|
|
|
325
325
|
class:bx--list-box__wrapper--inline={inline}
|
|
326
326
|
class:bx--multi-select__wrapper--inline--invalid={inline && invalid}
|
|
327
327
|
>
|
|
328
|
-
{#if
|
|
328
|
+
{#if labelText || $$slots.labelText}
|
|
329
329
|
<label
|
|
330
330
|
for={id}
|
|
331
331
|
class:bx--label={true}
|
|
332
332
|
class:bx--label--disabled={disabled}
|
|
333
333
|
class:bx--visually-hidden={hideLabel}
|
|
334
334
|
>
|
|
335
|
-
<slot name="
|
|
336
|
-
{
|
|
335
|
+
<slot name="labelText">
|
|
336
|
+
{labelText}
|
|
337
337
|
</slot>
|
|
338
338
|
</label>
|
|
339
339
|
{/if}
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
export let helperText = "";
|
|
75
75
|
|
|
76
76
|
/** Specify the label text */
|
|
77
|
-
export let
|
|
77
|
+
export let labelText = "";
|
|
78
78
|
|
|
79
79
|
/** Set to `true` to visually hide the label text */
|
|
80
80
|
export let hideLabel = false;
|
|
@@ -240,14 +240,14 @@
|
|
|
240
240
|
class:bx--number--sm={size === "sm"}
|
|
241
241
|
class:bx--number--xl={size === "xl"}
|
|
242
242
|
>
|
|
243
|
-
{#if $$slots.
|
|
243
|
+
{#if $$slots.labelText || labelText}
|
|
244
244
|
<label
|
|
245
245
|
for={id}
|
|
246
246
|
class:bx--label={true}
|
|
247
247
|
class:bx--label--disabled={disabled}
|
|
248
248
|
class:bx--visually-hidden={hideLabel}
|
|
249
249
|
>
|
|
250
|
-
<slot name="
|
|
250
|
+
<slot name="labelText">{labelText}</slot>
|
|
251
251
|
</label>
|
|
252
252
|
{/if}
|
|
253
253
|
<div
|
|
@@ -263,7 +263,7 @@
|
|
|
263
263
|
aria-describedby={errorId}
|
|
264
264
|
data-invalid={hasError || undefined}
|
|
265
265
|
aria-invalid={hasError || undefined}
|
|
266
|
-
aria-label={
|
|
266
|
+
aria-label={labelText ? undefined : ariaLabel}
|
|
267
267
|
{disabled}
|
|
268
268
|
{id}
|
|
269
269
|
{name}
|
|
@@ -286,7 +286,7 @@
|
|
|
286
286
|
aria-describedby={errorId}
|
|
287
287
|
data-invalid={hasError || undefined}
|
|
288
288
|
aria-invalid={hasError || undefined}
|
|
289
|
-
aria-label={
|
|
289
|
+
aria-label={labelText ? undefined : ariaLabel}
|
|
290
290
|
{disabled}
|
|
291
291
|
{id}
|
|
292
292
|
{name}
|
|
@@ -57,7 +57,7 @@ type $Props<Item> = {
|
|
|
57
57
|
* Specify the title text of the combobox
|
|
58
58
|
* @default ""
|
|
59
59
|
*/
|
|
60
|
-
|
|
60
|
+
labelText?: string;
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* Set to `true` to visually hide the label text
|
|
@@ -130,7 +130,14 @@ type $Props<Item> = {
|
|
|
130
130
|
clearFilterOnOpen?: boolean;
|
|
131
131
|
|
|
132
132
|
/**
|
|
133
|
-
*
|
|
133
|
+
* Set to `true` to enable autocomplete with typeahead
|
|
134
|
+
* @default false
|
|
135
|
+
*/
|
|
136
|
+
typeahead?: boolean;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Determine if an item should be filtered given the current combobox value.
|
|
140
|
+
* Will be ignored if `typeahead` is enabled.
|
|
134
141
|
*/
|
|
135
142
|
shouldFilterItem?: (item: Item, value: string) => boolean;
|
|
136
143
|
|
|
@@ -195,7 +202,7 @@ export default class ComboBox<
|
|
|
195
202
|
paste: WindowEventMap["paste"];
|
|
196
203
|
scroll: WindowEventMap["scroll"];
|
|
197
204
|
},
|
|
198
|
-
{ default: { item: Item; index: number };
|
|
205
|
+
{ default: { item: Item; index: number }; labelText: Record<string, never> }
|
|
199
206
|
> {
|
|
200
207
|
/**
|
|
201
208
|
* Clear the combo box programmatically
|
|
@@ -144,10 +144,10 @@ type $Props<Item> = {
|
|
|
144
144
|
) => string;
|
|
145
145
|
|
|
146
146
|
/**
|
|
147
|
-
* Specify the
|
|
147
|
+
* Specify the label text
|
|
148
148
|
* @default ""
|
|
149
149
|
*/
|
|
150
|
-
|
|
150
|
+
labelText?: string;
|
|
151
151
|
|
|
152
152
|
/**
|
|
153
153
|
* Set to `true` to pass the item to `itemToString` in the checkbox
|
|
@@ -263,5 +263,5 @@ export default class MultiSelect<
|
|
|
263
263
|
focus: WindowEventMap["focus"];
|
|
264
264
|
paste: WindowEventMap["paste"];
|
|
265
265
|
},
|
|
266
|
-
{ default: { item: Item; index: number };
|
|
266
|
+
{ default: { item: Item; index: number }; labelText: Record<string, never> }
|
|
267
267
|
> {}
|
|
@@ -114,7 +114,7 @@ type $Props = {
|
|
|
114
114
|
* Specify the label text
|
|
115
115
|
* @default ""
|
|
116
116
|
*/
|
|
117
|
-
|
|
117
|
+
labelText?: string;
|
|
118
118
|
|
|
119
119
|
/**
|
|
120
120
|
* Set to `true` to visually hide the label text
|
|
@@ -165,7 +165,7 @@ export default class NumberInput extends SvelteComponentTyped<
|
|
|
165
165
|
blur: WindowEventMap["blur"];
|
|
166
166
|
paste: WindowEventMap["paste"];
|
|
167
167
|
},
|
|
168
|
-
{
|
|
168
|
+
{ labelText: Record<string, never> }
|
|
169
169
|
> {
|
|
170
170
|
/**
|
|
171
171
|
* Default translation ids
|