carbon-components-svelte 0.88.3 → 0.89.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-components-svelte",
3
- "version": "0.88.3",
3
+ "version": "0.89.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Svelte implementation of the Carbon Design System",
6
6
  "type": "module",
@@ -46,6 +46,9 @@
46
46
  /** Specify the title text of the combobox */
47
47
  export let titleText = "";
48
48
 
49
+ /** Set to `true` to visually hide the label text */
50
+ export let hideLabel = false;
51
+
49
52
  /** Specify the placeholder text */
50
53
  export let placeholder = "";
51
54
 
@@ -226,7 +229,12 @@
226
229
 
227
230
  <div class:bx--list-box__wrapper={true}>
228
231
  {#if titleText || $$slots.titleText}
229
- <label for={id} class:bx--label={true} class:bx--label--disabled={disabled}>
232
+ <label
233
+ for={id}
234
+ class:bx--label={true}
235
+ class:bx--label--disabled={disabled}
236
+ class:bx--visually-hidden={hideLabel}
237
+ >
230
238
  <slot name="titleText">
231
239
  {titleText}
232
240
  </slot>
@@ -25,6 +25,7 @@
25
25
  class:bx--list-box__menu-item--active={active}
26
26
  class:bx--list-box__menu-item--highlighted={highlighted || active}
27
27
  aria-selected={active}
28
+ aria-disabled={disabled ? true : undefined}
28
29
  disabled={disabled ? true : undefined}
29
30
  {...$$restProps}
30
31
  on:click
@@ -44,11 +44,12 @@
44
44
  $: if (ctx && ref) {
45
45
  ctx.declareRef({ key: "selection", ref });
46
46
  }
47
-
48
- $: translationId = selectionCount
49
- ? translationIds.clearAll
50
- : translationIds.clearSelection;
51
-
47
+ $: translationId =
48
+ selectionCount === undefined
49
+ ? translationIds.clearSelection
50
+ : translationIds.clearAll;
51
+ $: buttonLabel =
52
+ translateWithId?.(translationId) ?? defaultTranslations[translationId];
52
53
  $: description =
53
54
  translateWithId?.(translationId) ?? defaultTranslations[translationId];
54
55
  </script>
@@ -79,7 +80,7 @@
79
80
  }
80
81
  }}
81
82
  {disabled}
82
- aria-label={translationIds.clearAll}
83
+ aria-label={buttonLabel}
83
84
  title={description}
84
85
  >
85
86
  <Close />
@@ -71,6 +71,8 @@
71
71
  required={$groupRequired ?? required}
72
72
  {value}
73
73
  class:bx--radio-button={true}
74
+ on:focus
75
+ on:blur
74
76
  on:change
75
77
  on:change={() => {
76
78
  if (update) {
@@ -5,8 +5,12 @@
5
5
  */
6
6
  export let value = "";
7
7
 
8
- /** Specify the option text */
9
- export let text = "";
8
+ /**
9
+ * Specify the option text
10
+ * If not specified, the value will be used as the text.
11
+ * @type {string}
12
+ */
13
+ export let text = undefined;
10
14
 
11
15
  /** Set to `true` to hide the option */
12
16
  export let hidden = false;
@@ -71,7 +71,7 @@
71
71
  on:mouseleave
72
72
  class:bx--form-item={true}
73
73
  >
74
- {#if (labelText || $$slots.labelText) && !hideLabel}
74
+ {#if labelText || $$slots.labelText}
75
75
  <div class:bx--text-area__label-wrapper={true}>
76
76
  <label
77
77
  for={id}
@@ -36,6 +36,7 @@
36
36
  const { add, update, selectedValue, groupName, groupRequired } = getContext(
37
37
  "TileGroup",
38
38
  ) ?? {
39
+ add: () => {},
39
40
  groupName: readable(undefined),
40
41
  groupRequired: readable(undefined),
41
42
  selectedValue: readable(checked ? value : undefined),
@@ -13,35 +13,22 @@
13
13
  export function toHierarchy(flatArray, getParentId) {
14
14
  /** @type {NodeLike[]} */
15
15
  const tree = [];
16
- const childrenOf = new Map();
17
- const itemsMap = new Map(flatArray.map((item) => [item.id, item]));
16
+ const nodeMap = new Map();
18
17
 
19
- flatArray.forEach((item) => {
18
+ for (const item of flatArray) {
20
19
  const parentId = getParentId(item);
20
+ nodeMap.set(item.id, item);
21
21
 
22
- // Only create nodes array if we have children.
23
- const children = childrenOf.get(item.id);
24
- if (children) {
25
- item.nodes = children;
26
- }
27
-
28
- // Check if parentId exists using Map instead of array lookup.
29
- const parentExists = parentId && itemsMap.has(parentId);
30
-
31
- if (parentId && parentExists) {
32
- if (!childrenOf.has(parentId)) {
33
- childrenOf.set(parentId, []);
34
- }
35
- childrenOf.get(parentId).push(item);
36
-
37
- const parent = itemsMap.get(parentId);
38
- if (parent) {
39
- parent.nodes = childrenOf.get(parentId);
40
- }
41
- } else {
22
+ if (!parentId || !nodeMap.has(parentId)) {
42
23
  tree.push(item);
24
+ } else {
25
+ const parent = nodeMap.get(parentId);
26
+ if (!parent.nodes) {
27
+ parent.nodes = [];
28
+ }
29
+ parent.nodes.push(item);
43
30
  }
44
- });
31
+ }
45
32
 
46
33
  return tree;
47
34
  }
@@ -60,6 +60,12 @@ type $Props = {
60
60
  */
61
61
  titleText?: string;
62
62
 
63
+ /**
64
+ * Set to `true` to visually hide the label text
65
+ * @default false
66
+ */
67
+ hideLabel?: boolean;
68
+
63
69
  /**
64
70
  * Specify the placeholder text
65
71
  * @default ""
@@ -71,6 +71,10 @@ export type RadioButtonProps = Omit<$RestProps, keyof $Props> & $Props;
71
71
 
72
72
  export default class RadioButton extends SvelteComponentTyped<
73
73
  RadioButtonProps,
74
- { change: WindowEventMap["change"] },
74
+ {
75
+ focus: WindowEventMap["focus"];
76
+ blur: WindowEventMap["blur"];
77
+ change: WindowEventMap["change"];
78
+ },
75
79
  { labelText: {} }
76
80
  > {}
@@ -9,7 +9,8 @@ export type SelectItemProps = {
9
9
 
10
10
  /**
11
11
  * Specify the option text
12
- * @default ""
12
+ * If not specified, the value will be used as the text.
13
+ * @default undefined
13
14
  */
14
15
  text?: string;
15
16