@ni/nimble-components 17.1.0 → 18.0.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.
@@ -15541,6 +15541,9 @@
15541
15541
  iconSize: 'icon-size',
15542
15542
  groupHeaderTextTransform: 'group-header-text-transform',
15543
15543
  drawerWidth: 'drawer-width',
15544
+ spinnerSmallHeight: 'spinner-small-height',
15545
+ spinnerMediumHeight: 'spinner-medium-height',
15546
+ spinnerLargeHeight: 'spinner-large-height',
15544
15547
  smallDelay: 'small-delay',
15545
15548
  mediumDelay: 'medium-delay',
15546
15549
  largeDelay: 'large-delay',
@@ -15810,6 +15813,9 @@
15810
15813
  const borderWidth = DesignToken.create(styleNameFromTokenName(tokenNames.borderWidth)).withDefault('1px');
15811
15814
  const iconSize = DesignToken.create(styleNameFromTokenName(tokenNames.iconSize)).withDefault('16px');
15812
15815
  const drawerWidth = DesignToken.create(styleNameFromTokenName(tokenNames.drawerWidth)).withDefault('784px');
15816
+ const spinnerSmallHeight = DesignToken.create(styleNameFromTokenName(tokenNames.spinnerSmallHeight)).withDefault('16px');
15817
+ DesignToken.create(styleNameFromTokenName(tokenNames.spinnerMediumHeight)).withDefault('32px');
15818
+ DesignToken.create(styleNameFromTokenName(tokenNames.spinnerLargeHeight)).withDefault('64px');
15813
15819
  // Drop Shadow Tokens
15814
15820
  DesignToken.create(styleNameFromTokenName(tokenNames.elevation1BoxShadow)).withDefault((element) => `0px 1px 4px ${hexToRgbaCssColor(getColorForTheme(element, Black, Black, Black), 0.16)}`);
15815
15821
  const elevation2BoxShadow = DesignToken.create(styleNameFromTokenName(tokenNames.elevation2BoxShadow)).withDefault((element) => `0px 2px 4px ${hexToRgbaCssColor(getColorForTheme(element, Black, Black, Black), 0.16)}`);
@@ -21232,7 +21238,7 @@
21232
21238
  ${ref('region')}
21233
21239
  >
21234
21240
  <span part="menu">
21235
- <slot name="menu" ${slotted({ property: 'slottedMenus', filter: elements('[role=menu]') })}></slot>
21241
+ <slot name="menu" ${slotted({ property: 'slottedMenus' })}></slot>
21236
21242
  </span>
21237
21243
  </${DesignSystem.tagFor(AnchoredRegion)}>
21238
21244
  `)}
@@ -21275,7 +21281,7 @@
21275
21281
  */
21276
21282
  this.focusLastItemWhenOpened = false;
21277
21283
  this.menuChangeHandler = () => {
21278
- this.open = false;
21284
+ this.setOpen(false);
21279
21285
  this.toggleButton.focus();
21280
21286
  };
21281
21287
  }
@@ -21310,7 +21316,11 @@
21310
21316
  if (!this.open) {
21311
21317
  // Only fire an event here if the menu is changing to being closed. Otherwise,
21312
21318
  // wait until the menu is actually opened before firing the event.
21313
- this.$emit('open-change');
21319
+ const eventDetail = {
21320
+ oldState: true,
21321
+ newState: false
21322
+ };
21323
+ this.$emit('toggle', eventDetail);
21314
21324
  }
21315
21325
  }
21316
21326
  regionLoadedHandler() {
@@ -21321,23 +21331,28 @@
21321
21331
  else {
21322
21332
  this.focusMenu();
21323
21333
  }
21324
- this.$emit('open-change');
21334
+ const eventDetail = {
21335
+ oldState: false,
21336
+ newState: true
21337
+ };
21338
+ this.$emit('toggle', eventDetail);
21325
21339
  }
21326
21340
  focusoutHandler(e) {
21327
21341
  if (!this.open) {
21328
21342
  return true;
21329
21343
  }
21330
21344
  const focusTarget = e.relatedTarget;
21331
- if (!this.contains(focusTarget)) {
21332
- this.open = false;
21345
+ if (!this.contains(focusTarget)
21346
+ && !this.getMenu()?.contains(focusTarget)) {
21347
+ this.setOpen(false);
21333
21348
  return false;
21334
21349
  }
21335
21350
  return true;
21336
21351
  }
21337
21352
  toggleButtonCheckedChangeHandler(e) {
21338
- this.open = this.toggleButton.checked;
21353
+ this.setOpen(this.toggleButton.checked);
21339
21354
  // Don't bubble the 'change' event from the toggle button because
21340
- // the menu button has its own 'open-change' event.
21355
+ // the menu button has its own 'toggle' event.
21341
21356
  e.stopPropagation();
21342
21357
  return false;
21343
21358
  }
@@ -21345,10 +21360,10 @@
21345
21360
  switch (e.key) {
21346
21361
  case keyArrowUp:
21347
21362
  this.focusLastItemWhenOpened = true;
21348
- this.open = true;
21363
+ this.setOpen(true);
21349
21364
  return false;
21350
21365
  case keyArrowDown:
21351
- this.open = true;
21366
+ this.setOpen(true);
21352
21367
  return false;
21353
21368
  default:
21354
21369
  return true;
@@ -21357,21 +21372,59 @@
21357
21372
  menuKeyDownHandler(e) {
21358
21373
  switch (e.key) {
21359
21374
  case keyEscape:
21360
- this.open = false;
21375
+ this.setOpen(false);
21361
21376
  this.toggleButton.focus();
21362
21377
  return false;
21363
21378
  default:
21364
21379
  return true;
21365
21380
  }
21366
21381
  }
21367
- get menu() {
21368
- return this.slottedMenus?.length ? this.slottedMenus[0] : undefined;
21382
+ setOpen(newValue) {
21383
+ if (this.open === newValue) {
21384
+ return;
21385
+ }
21386
+ const eventDetail = {
21387
+ oldState: this.open,
21388
+ newState: newValue
21389
+ };
21390
+ this.$emit('beforetoggle', eventDetail);
21391
+ this.open = newValue;
21392
+ }
21393
+ getMenu() {
21394
+ // Get the menu that is slotted within the menu-button, taking into account
21395
+ // that it may be nested within multiple 'slot' elements, such as when used
21396
+ // within a table.
21397
+ if (!this.slottedMenus?.length) {
21398
+ return undefined;
21399
+ }
21400
+ let currentItem = this.slottedMenus[0];
21401
+ while (currentItem) {
21402
+ if (currentItem.getAttribute('role') === 'menu') {
21403
+ return currentItem;
21404
+ }
21405
+ if (this.isSlotElement(currentItem)) {
21406
+ const firstNode = currentItem.assignedNodes()[0];
21407
+ if (firstNode instanceof HTMLElement) {
21408
+ currentItem = firstNode;
21409
+ }
21410
+ else {
21411
+ currentItem = undefined;
21412
+ }
21413
+ }
21414
+ else {
21415
+ return undefined;
21416
+ }
21417
+ }
21418
+ return undefined;
21419
+ }
21420
+ isSlotElement(element) {
21421
+ return element?.nodeName === 'SLOT';
21369
21422
  }
21370
21423
  focusMenu() {
21371
- this.menu?.focus();
21424
+ this.getMenu()?.focus();
21372
21425
  }
21373
21426
  focusLastMenuItem() {
21374
- const menuItems = this.menu?.querySelectorAll('[role=menuitem]');
21427
+ const menuItems = this.getMenu()?.querySelectorAll('[role=menuitem]');
21375
21428
  if (menuItems?.length) {
21376
21429
  const lastMenuItem = menuItems[menuItems.length - 1];
21377
21430
  lastMenuItem.focus();
@@ -22022,8 +22075,8 @@
22022
22075
  ${display('inline-flex')}
22023
22076
 
22024
22077
  :host {
22025
- width: 16px;
22026
- height: 16px;
22078
+ height: ${spinnerSmallHeight};
22079
+ aspect-ratio: 1 / 1;
22027
22080
  }
22028
22081
 
22029
22082
  div.container {