@microsoft/fabric-slicers 4.2.0 → 4.4.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/CHANGELOG CHANGED
@@ -5,6 +5,15 @@ All notable changes to `@microsoft/fabric-slicers` will be documented in this fi
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## 4.4.0 - 2026-11-17
9
+
10
+ - Consolidate DataCell types in visuals-core
11
+
12
+ ## 4.3.0 - 2026-11-11
13
+
14
+ - Fix duplicate slicer search focus indicators
15
+ - Identify list and dropdown slicer items by group-on keys
16
+
8
17
  ## 4.2.0 - 2026-11-05
9
18
 
10
19
  - Update date slicer dropdown formatting and preset labels
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ReactElement } from 'react';
2
- import { CalendarDate, DataTable, VisualTheme, InteractionEventCallback } from '@microsoft/fabric-visuals-core';
2
+ import { CalendarDate, DataTable, VisualTheme, InteractionEventCallback, DataCell } from '@microsoft/fabric-visuals-core';
3
3
 
4
4
  /** Supported raw slicer values. Null and undefined share one blank entry in list and dropdown slicers. */
5
5
  type SlicerValue = string | number | boolean | Date | null | undefined;
@@ -34,12 +34,28 @@ interface ListSlicerDisplayOptions extends SlicerDisplayOptions {
34
34
  interface ListSlicerInputParams extends SlicerInputParams {
35
35
  displayOptions?: ListSlicerDisplayOptions;
36
36
  /**
37
- * Raw selected values to restore or synchronize without emitting events.
37
+ * DataTable columns that identify an item, such as the group-on keys from InteractionManager.getIdentityFields([column]).
38
+ * An item is one combination of the `column` value and these columns' values, so two items can share a label.
39
+ * Each selected item is emitted as its own selection with one value for `column` and for each key column.
40
+ * Omitted, empty, or only `column` keeps one item per value. Changing it resets local selection.
41
+ */
42
+ keyColumns?: readonly string[];
43
+ /**
44
+ * Selected values to restore or synchronize without emitting events.
38
45
  * Null resets to all, including future values. An empty array selects none.
39
46
  * Selected values absent from refreshed data are retained until changed or cleared.
40
47
  * Omitted leaves selection locally managed; supplying values does not disable local edits.
48
+ * With key columns, pass keyed items; raw values throw, since a label alone can't identify one item.
49
+ * Keyed items given to a slicer without key columns select by `label`.
41
50
  */
42
- selection?: readonly SlicerValue[] | null;
51
+ selection?: readonly SlicerValue[] | readonly SlicerKeyedItem[] | null;
52
+ }
53
+ /** One selected item of a list or dropdown slicer with key columns. */
54
+ interface SlicerKeyedItem {
55
+ /** Values of the key columns other than the slicer's `column`, by column name. Other entries are ignored. */
56
+ readonly keys: Readonly<Record<string, SlicerValue>>;
57
+ /** Value of the slicer's `column`. It is emitted with the keys, including while the item is absent from the data. */
58
+ readonly label: SlicerValue;
43
59
  }
44
60
  /** Inputs for the dropdown slicer. */
45
61
  interface DropdownSlicerInputParams extends ListSlicerInputParams {
@@ -106,6 +122,6 @@ declare function DateSlicer(props: DateSlicerInputParams): ReactElement;
106
122
  declare function RangeSlicer({ data, column, title, theme, step, disabled, displayOptions, onInteraction, selection, }: RangeSlicerInputParams): ReactElement;
107
123
 
108
124
  /** Narrows unvalidated data cells and interaction values to supported slicer values. */
109
- declare function isSlicerValue(value: DataTable['rows'][number][number]): value is SlicerValue;
125
+ declare function isSlicerValue(value: DataCell): value is SlicerValue;
110
126
 
111
- export { type CalendarDateRange, DateSlicer, type DateSlicerDisplayOptions, type DateSlicerInputParams, DropdownSlicer, type DropdownSlicerInputParams, ListSlicer, type ListSlicerDisplayOptions, type ListSlicerInputParams, RangeSlicer, type RangeSlicerDisplayOptions, type RangeSlicerInputParams, type SlicerDisplayOptions, type SlicerInputParams, type SlicerRange, type SlicerValue, isSlicerValue };
127
+ export { type CalendarDateRange, DateSlicer, type DateSlicerDisplayOptions, type DateSlicerInputParams, DropdownSlicer, type DropdownSlicerInputParams, ListSlicer, type ListSlicerDisplayOptions, type ListSlicerInputParams, RangeSlicer, type RangeSlicerDisplayOptions, type RangeSlicerInputParams, type SlicerDisplayOptions, type SlicerInputParams, type SlicerKeyedItem, type SlicerRange, type SlicerValue, isSlicerValue };
package/dist/index.js CHANGED
@@ -13,26 +13,53 @@ function isSlicerValue(value) {
13
13
  }
14
14
 
15
15
  // src/hooks/use-list-slicer.ts
16
+ var noKeyValues = Object.freeze([]);
17
+ var invalidSelectionMessage = "Slicer selection must contain text, finite numbers, booleans, valid dates, or blanks.";
16
18
  function valueKey(value) {
17
19
  if (value == null) return "blank";
18
20
  if (value instanceof Date) return `date:${value.getTime()}`;
19
21
  return `${typeof value}:${String(value)}`;
20
22
  }
21
- function prepareListSlicerData({ data, column, title }) {
23
+ function itemKey(value, keyValues) {
24
+ if (keyValues.length === 0) return valueKey(value);
25
+ return JSON.stringify([value, ...keyValues].map(valueKey));
26
+ }
27
+ function getListSlicerIdentityKey({ column, keyColumns }) {
28
+ return JSON.stringify([column, keyColumns ?? []]);
29
+ }
30
+ function getOtherKeyColumns(column, serializedKeyColumns) {
31
+ const keyColumns = JSON.parse(serializedKeyColumns);
32
+ return [...new Set(keyColumns)].filter((keyColumn) => keyColumn !== column);
33
+ }
34
+ function prepareListSlicerData({ data, column, title }, otherKeyColumns) {
22
35
  let resolvedTitle = title ?? column;
23
36
  let format;
24
37
  let valueCount;
25
38
  let valueAt;
39
+ let keyValuesAt = () => noKeyValues;
26
40
  if (isDataTable(data)) {
27
41
  const columnIndex = data.columns.findIndex((candidate) => candidate.name === column);
28
42
  if (columnIndex < 0) {
29
43
  return { title: resolvedTitle, items: [], error: formatString("Slicer_MissingColumn", column) };
30
44
  }
31
45
  resolvedTitle = title ?? data.columns[columnIndex].displayName ?? column;
46
+ const keyIndexes = otherKeyColumns.map(
47
+ (keyColumn) => data.columns.findIndex((candidate) => candidate.name === keyColumn)
48
+ );
49
+ const missingKeyIndex = keyIndexes.indexOf(-1);
50
+ if (missingKeyIndex >= 0) {
51
+ return { title: resolvedTitle, items: [], error: formatString("Slicer_MissingColumn", otherKeyColumns[missingKeyIndex]) };
52
+ }
32
53
  format = data.columns[columnIndex].format;
33
54
  valueCount = data.rows.length;
34
55
  valueAt = (index) => data.rows[index][columnIndex];
56
+ if (keyIndexes.length > 0) {
57
+ keyValuesAt = (index) => keyIndexes.map((keyIndex) => data.rows[index][keyIndex]);
58
+ }
35
59
  } else if (Array.isArray(data)) {
60
+ if (otherKeyColumns.length > 0) {
61
+ return { title: resolvedTitle, items: [], error: formatString("Slicer_MissingColumn", otherKeyColumns[0]) };
62
+ }
36
63
  valueCount = data.length;
37
64
  valueAt = (index) => data[index];
38
65
  } else {
@@ -42,41 +69,84 @@ function prepareListSlicerData({ data, column, title }) {
42
69
  const seenKeys = /* @__PURE__ */ new Set();
43
70
  for (let index = 0; index < valueCount; index++) {
44
71
  const value = valueAt(index);
45
- if (!isSlicerValue(value)) {
72
+ const keyValues = keyValuesAt(index);
73
+ if (!isSlicerValue(value) || !keyValues.every(isSlicerValue)) {
46
74
  return { title: resolvedTitle, items: [], error: getString("Slicer_InvalidData") };
47
75
  }
48
- const key = valueKey(value);
76
+ const key = itemKey(value, keyValues);
49
77
  if (seenKeys.has(key)) continue;
50
78
  seenKeys.add(key);
51
79
  const label = value == null || value === "" ? getString("Slicer_Blank") : String(formatValue(value, format));
52
- items.push({ key, value, label });
80
+ items.push({ key, value, keyValues, label });
53
81
  }
54
82
  return { title: resolvedTitle, items };
55
83
  }
56
- function useListSlicer({ data, column, title, selection, onInteraction }) {
84
+ function resolveKeyedItem(entry, otherKeyColumns) {
85
+ if (typeof entry !== "object" || entry instanceof Date || !isSlicerValue(entry.label)) {
86
+ throw new Error(invalidSelectionMessage);
87
+ }
88
+ const keyValues = otherKeyColumns.map((keyColumn) => {
89
+ if (!Object.hasOwn(entry.keys, keyColumn)) {
90
+ throw new Error(`Slicer selection item is missing key column ${JSON.stringify(keyColumn)}.`);
91
+ }
92
+ const keyValue = entry.keys[keyColumn];
93
+ if (!isSlicerValue(keyValue)) throw new Error(invalidSelectionMessage);
94
+ return keyValue;
95
+ });
96
+ return { value: entry.label, keyValues };
97
+ }
98
+ function resolveHostSelection(selection, otherKeyColumns) {
99
+ const resolved = /* @__PURE__ */ new Map();
100
+ for (const entry of selection) {
101
+ let selected;
102
+ if (isSlicerValue(entry)) {
103
+ if (otherKeyColumns.length > 0) {
104
+ throw new Error("Slicer selection must contain keyed items, not raw values, when the slicer has key columns.");
105
+ }
106
+ selected = { value: entry, keyValues: noKeyValues };
107
+ } else {
108
+ selected = resolveKeyedItem(entry, otherKeyColumns);
109
+ }
110
+ const key = itemKey(selected.value, selected.keyValues);
111
+ if (!resolved.has(key)) resolved.set(key, selected);
112
+ }
113
+ return resolved;
114
+ }
115
+ function toSemanticSelections(column, otherKeyColumns, selected) {
116
+ const items = [...selected.values()];
117
+ if (otherKeyColumns.length === 0) {
118
+ return [{ predicates: [{ type: "set", fieldId: column, values: items.map((item) => toInteractionValue(item.value)) }] }];
119
+ }
120
+ return items.map((item) => ({
121
+ predicates: [
122
+ { type: "set", fieldId: column, values: [toInteractionValue(item.value)] },
123
+ ...otherKeyColumns.map((keyColumn, index) => ({
124
+ type: "set",
125
+ fieldId: keyColumn,
126
+ values: [toInteractionValue(item.keyValues[index])]
127
+ }))
128
+ ]
129
+ }));
130
+ }
131
+ function useListSlicer({ data, column, title, keyColumns, selection, onInteraction }) {
132
+ const serializedKeyColumns = JSON.stringify(keyColumns ?? []);
133
+ const otherKeyColumns = useMemo(
134
+ () => getOtherKeyColumns(column, serializedKeyColumns),
135
+ [column, serializedKeyColumns]
136
+ );
57
137
  const prepared = useMemo(
58
- () => prepareListSlicerData({ data, column, title }),
59
- [data, column, title]
138
+ () => prepareListSlicerData({ data, column, title }, otherKeyColumns),
139
+ [data, column, title, otherKeyColumns]
60
140
  );
61
- const valuesByKey = useMemo(
62
- () => new Map(prepared.items.map((item) => [item.key, item.value])),
141
+ const itemsByKey = useMemo(
142
+ () => new Map(prepared.items.map((item) => [item.key, item])),
63
143
  [prepared.items]
64
144
  );
65
145
  const resolvedSelection = useMemo(() => {
66
- if (selection !== void 0) {
67
- if (selection === null) return "all";
68
- if (!selection.every(isSlicerValue)) {
69
- throw new Error("Slicer selection must contain text, finite numbers, booleans, valid dates, or blanks.");
70
- }
71
- const resolved = /* @__PURE__ */ new Map();
72
- for (const value of selection) {
73
- const key = valueKey(value);
74
- if (!resolved.has(key)) resolved.set(key, value);
75
- }
76
- return resolved;
77
- }
78
- return void 0;
79
- }, [selection]);
146
+ if (selection === void 0) return void 0;
147
+ if (selection === null) return "all";
148
+ return resolveHostSelection(selection, otherKeyColumns);
149
+ }, [selection, otherKeyColumns]);
80
150
  const [localSelection, setLocalSelection] = useState(resolvedSelection ?? "all");
81
151
  const selectionRef = useRef(resolvedSelection ?? "all");
82
152
  useEffect(() => {
@@ -97,42 +167,35 @@ function useListSlicer({ data, column, title, selection, onInteraction }) {
97
167
  selectionRef.current = next;
98
168
  setLocalSelection(next);
99
169
  if (!onInteraction) return;
100
- const event = next === "all" || next.size === 0 ? { action: "clear" } : {
101
- action: "select",
102
- selections: [{
103
- predicates: [{
104
- type: "set",
105
- fieldId: column,
106
- values: [...next.values()].map(toInteractionValue)
107
- }]
108
- }]
109
- };
170
+ const event = next === "all" || next.size === 0 ? { action: "clear" } : { action: "select", selections: toSemanticSelections(column, otherKeyColumns, next) };
110
171
  onInteraction([event]);
111
- }, [column, onInteraction]);
172
+ }, [column, otherKeyColumns, onInteraction]);
112
173
  const updateSelection = useCallback((next) => {
113
174
  const normalized = next !== "all" && prepared.items.length > 0 && next.size >= prepared.items.length && prepared.items.every((item) => next.has(item.key)) ? "all" : next;
114
175
  commitSelection(normalized);
115
176
  }, [commitSelection, prepared.items]);
116
177
  const selectOnly = useCallback((key) => {
117
- if (!valuesByKey.has(key)) throw new Error(`Cannot update an unknown slicer key: ${key}`);
178
+ const item = itemsByKey.get(key);
179
+ if (item === void 0) throw new Error(`Cannot update an unknown slicer key: ${key}`);
118
180
  const previous = selectionRef.current;
119
181
  if (previous !== "all" && previous.size === 1 && previous.has(key)) return;
120
- commitSelection(/* @__PURE__ */ new Map([[key, valuesByKey.get(key)]]));
121
- }, [valuesByKey, commitSelection]);
182
+ commitSelection(/* @__PURE__ */ new Map([[key, item]]));
183
+ }, [itemsByKey, commitSelection]);
122
184
  const clear = useCallback(() => {
123
185
  if (selectionRef.current !== "all") updateSelection("all");
124
186
  }, [updateSelection]);
125
187
  const toggle = useCallback((key, checked) => {
126
- if (!valuesByKey.has(key)) throw new Error(`Cannot update an unknown slicer key: ${key}`);
188
+ const item = itemsByKey.get(key);
189
+ if (item === void 0) throw new Error(`Cannot update an unknown slicer key: ${key}`);
127
190
  const previous = selectionRef.current;
128
191
  if ((previous === "all" || previous.has(key)) === checked) return;
129
- const next = new Map(previous === "all" ? valuesByKey : previous);
130
- if (checked) next.set(key, valuesByKey.get(key));
192
+ const next = new Map(previous === "all" ? itemsByKey : previous);
193
+ if (checked) next.set(key, item);
131
194
  else next.delete(key);
132
195
  updateSelection(next);
133
- }, [valuesByKey, updateSelection]);
196
+ }, [itemsByKey, updateSelection]);
134
197
  const toggleAll = useCallback((checked, keys) => {
135
- if (valuesByKey.size === 0 || keys?.length === 0) return;
198
+ if (itemsByKey.size === 0 || keys?.length === 0) return;
136
199
  if (keys === void 0 && checked) {
137
200
  clear();
138
201
  return;
@@ -143,15 +206,16 @@ function useListSlicer({ data, column, title, selection, onInteraction }) {
143
206
  return;
144
207
  }
145
208
  let next;
146
- for (const key of keys ?? valuesByKey.keys()) {
147
- if (!valuesByKey.has(key)) throw new Error(`Cannot update an unknown slicer key: ${key}`);
209
+ for (const key of keys ?? itemsByKey.keys()) {
210
+ const item = itemsByKey.get(key);
211
+ if (item === void 0) throw new Error(`Cannot update an unknown slicer key: ${key}`);
148
212
  if ((previous === "all" || previous.has(key)) === checked) continue;
149
- next ??= new Map(previous === "all" ? valuesByKey : previous);
150
- if (checked) next.set(key, valuesByKey.get(key));
213
+ next ??= new Map(previous === "all" ? itemsByKey : previous);
214
+ if (checked) next.set(key, item);
151
215
  else next.delete(key);
152
216
  }
153
217
  if (next) updateSelection(next);
154
- }, [valuesByKey, clear, updateSelection]);
218
+ }, [itemsByKey, clear, updateSelection]);
155
219
  return {
156
220
  ...prepared,
157
221
  selectedItems,
@@ -427,7 +491,8 @@ var useListSlicerStyles = makeStyles3(inVisualsLayer3({
427
491
  // Draw the browser's focus ring around the icon and input without adding a Tab stop.
428
492
  ":has(> input:focus-visible)": {
429
493
  ...nativeFocusOutline,
430
- "& > input": { outline: "none" }
494
+ // The wrapper owns focus; host focus rules must not add an inner outline or shadow ring.
495
+ "& > input": { outline: "none !important", boxShadow: "none !important" }
431
496
  }
432
497
  },
433
498
  input: {
@@ -584,7 +649,7 @@ function virtualRowStyle(start) {
584
649
  return { position: "absolute", top: 0, left: 0, width: "100%", height: ROW_HEIGHT, transform: `translateY(${start}px)` };
585
650
  }
586
651
  function ListSlicer(props) {
587
- return /* @__PURE__ */ jsx4(StatefulListSlicer, { ...props }, props.column);
652
+ return /* @__PURE__ */ jsx4(StatefulListSlicer, { ...props }, getListSlicerIdentityKey(props));
588
653
  }
589
654
  function StatefulListSlicer(props) {
590
655
  const state = useListSlicer(props);
@@ -805,7 +870,7 @@ var useDropdownStyles = makeStyles5(inVisualsLayer5({
805
870
  // src/components/dropdown-slicer/dropdown-slicer.tsx
806
871
  import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
807
872
  function DropdownSlicer(props) {
808
- return /* @__PURE__ */ jsx6(DropdownSlicerContent, { ...props }, props.column);
873
+ return /* @__PURE__ */ jsx6(DropdownSlicerContent, { ...props }, getListSlicerIdentityKey(props));
809
874
  }
810
875
  function DropdownSlicerContent(props) {
811
876
  const state = useListSlicer(props);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@microsoft/fabric-slicers",
3
3
  "description": "Slicer components for Fabric Apps - Analytics",
4
- "version": "4.2.0",
4
+ "version": "4.4.0",
5
5
  "author": "Microsoft",
6
6
  "license": "MIT",
7
7
  "type": "module",
@@ -30,6 +30,6 @@
30
30
  "@tanstack/react-virtual": "^3.13.23",
31
31
  "lodash.debounce": "^4.0.8",
32
32
  "radix-ui": "^1.6.7",
33
- "@microsoft/fabric-visuals-core": "5.2.0"
33
+ "@microsoft/fabric-visuals-core": "5.4.0"
34
34
  }
35
35
  }