@milktop/react-ui 0.3.11 → 0.3.13

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.
@@ -61,6 +61,8 @@ function go(href) {
61
61
  link.click();
62
62
  link.remove();
63
63
  }
64
+ // Zag's own scrolling, off: the Command does its own (see below).
65
+ const noScroll = () => { };
64
66
  export function Command({ items = [], load = null, debounce = 200, onSelect, trigger = null, open: openProp, defaultOpen = false, onOpenChange, hotkey = 'k', navigate = null, label: labelProp, placeholder: placeholderProp, emptyText: emptyTextProp, loadingText: loadingTextProp, hints = true, scope = null, onScopeClear, className, classes, ...rest }) {
65
67
  const t = useMessages();
66
68
  const label = labelProp ?? t.command.label;
@@ -115,8 +117,7 @@ export function Command({ items = [], load = null, debounce = 200, onSelect, tri
115
117
  }
116
118
  // Keeps the highlighted item in view, scrolling only the list, and showing
117
119
  // a group's heading along with its first item.
118
- function scrollToItem({ getElement }) {
119
- const el = getElement();
120
+ function scrollToItem(el) {
120
121
  const box = listEl.current;
121
122
  if (!el || !box)
122
123
  return;
@@ -133,17 +134,23 @@ export function Command({ items = [], load = null, debounce = 200, onSelect, tri
133
134
  }
134
135
  // The value stays empty, so picking the same command again still counts.
135
136
  const list = useListbox({
136
- collection, value: [], loopFocus: true, scrollToIndexFn: scrollToItem, onSelect: (details) => choose(details.value),
137
+ collection, value: [], loopFocus: true, scrollToIndexFn: noScroll, onSelect: (details) => choose(details.value),
137
138
  });
138
139
  const api = useRef(list);
139
140
  useEffect(() => { api.current = list; });
141
+ // Zag scrolls only a list that was there when it started, and this one comes with the dialog: ours, on each highlight.
142
+ // An item highlighted by the pointer is already in view, so it doesn't move.
143
+ useEffect(() => {
144
+ scrollToItem(listEl.current?.querySelector('[data-part=item][data-highlighted]') ?? null);
145
+ }, [list.highlightedValue]);
140
146
  // Each time it opens (from the trigger, the hotkey or `open`): an empty
141
- // search over all the commands.
147
+ // search over all the commands. Emptied as it closes too, so a scope that
148
+ // changes as it opens again (below) doesn't bring back the last query.
142
149
  const latestSearch = useRef(search);
143
150
  useEffect(() => { latestSearch.current = search; });
144
151
  useEffect(() => {
145
152
  if (!open)
146
- return;
153
+ return setQuery('');
147
154
  setLoaded([]);
148
155
  latestSearch.current('');
149
156
  }, [open]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milktop/react-ui",
3
- "version": "0.3.11",
3
+ "version": "0.3.13",
4
4
  "description": "React components on Ark UI (Zag state machines), with imba-ui's API and design",
5
5
  "license": "MIT",
6
6
  "author": "André Goldstein",