@planningcenter/topbar 12.4.1-qa-980.1 → 12.4.1-qa-980.2

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/dist/topbar.js CHANGED
@@ -4444,6 +4444,8 @@ function hasSelectedText(element) {
4444
4444
  return selectedInField || ((_b = (_a = window.getSelection()) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : "") !== "";
4445
4445
  }
4446
4446
 
4447
+ const resultId = (listboxId, index) => `${listboxId}-result-${index}`;
4448
+
4447
4449
  // eslint-disable-next-line sort-keys-fix/sort-keys-fix
4448
4450
  const COPIED_TIMING = {
4449
4451
  enter: 240,
@@ -4488,7 +4490,7 @@ function indexOf(highlight, items, list) {
4488
4490
  // A list that grows, fills in, or reorders under the same `list` keeps its
4489
4491
  // highlight on the same item, found again by key.
4490
4492
  // Disabled, nothing is highlighted and the keys and pointer leave it alone.
4491
- function useResultNavigation(items, list, enabled = true) {
4493
+ function useResultNavigation(items, list, listboxId, enabled = true) {
4492
4494
  const [highlight, setHighlight] = React.useState({
4493
4495
  index: 0,
4494
4496
  list
@@ -4517,9 +4519,17 @@ function useResultNavigation(items, list, enabled = true) {
4517
4519
  highlightIndex((highlightedIndex + step + items.length) % items.length);
4518
4520
  } else if (event.key === "Enter" && highlighted && !event.nativeEvent.isComposing) {
4519
4521
  event.preventDefault();
4520
- open(highlighted.url, {
4521
- newTab: hasCommandKey(event)
4522
- });
4522
+ // Clicking the result's own link, rather than going to its URL, lets
4523
+ // routers like Turbo follow it as they would a click, and closes
4524
+ // search the same way.
4525
+ const link = hasCommandKey(event) ? null : document.getElementById(resultId(listboxId, highlightedIndex));
4526
+ if (link) {
4527
+ link.click();
4528
+ } else {
4529
+ open(highlighted.url, {
4530
+ newTab: hasCommandKey(event)
4531
+ });
4532
+ }
4523
4533
  } else if (isCopyShortcut(event) && highlighted && !hasSelectedText(event.currentTarget)) {
4524
4534
  event.preventDefault();
4525
4535
  copy(highlighted.url);
@@ -5382,8 +5392,6 @@ function EndOfResultsObserver({
5382
5392
  });
5383
5393
  }
5384
5394
 
5385
- const resultId = (listboxId, index) => `${listboxId}-result-${index}`;
5386
-
5387
5395
  var styles$e = {"result":"result-Thq2C","title":"title-KYUEn","subtitle":"subtitle-R2haq","image":"image-KVDor","avatar":"avatar-6Gh62","photo":"photo-FZR3Q","badge":"badge-trUKt"};
5388
5396
 
5389
5397
  function SearchResult({
@@ -6126,7 +6134,7 @@ function SearchPanel({
6126
6134
  // A narrow window with a keyboard and mouse keeps both, as does the desktop
6127
6135
  // layout on a touch device, whose keyboard hints still advertise them.
6128
6136
  const touchOnly = useMediaQuery("(hover: none) and (pointer: coarse)");
6129
- const navigation = useResultNavigation(items, hasTerm ? sections : RECENTS, !(mobile && touchOnly));
6137
+ const navigation = useResultNavigation(items, hasTerm ? sections : RECENTS, listboxId, !(mobile && touchOnly));
6130
6138
  const {
6131
6139
  highlightedIndex
6132
6140
  } = navigation;
@@ -6417,7 +6425,10 @@ function ProductSearch({
6417
6425
  env: env,
6418
6426
  // Phones have no Esc, so mobile search gets a close button.
6419
6427
  onClose: mobile ? () => setOpen(false) : undefined,
6420
- onOpenResult: () => setOpen(false),
6428
+ // Routers like Turbo follow the result's link from their own click
6429
+ // listeners, after this one, so the modal closes once they're done
6430
+ // with it. A microtask would run between listeners, too soon.
6431
+ onOpenResult: () => setTimeout(() => setOpen(false)),
6421
6432
  products: searchable.products
6422
6433
  })));
6423
6434
  }