@babylonjs/gui 7.15.2 → 7.16.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -348,6 +348,7 @@ export declare class AdvancedDynamicTexture extends DynamicTexture {
348
348
  private _translateToPicking;
349
349
  /** Attach to all scene events required to support pointer events */
350
350
  attach(): void;
351
+ private _focusProperties;
351
352
  private _focusNextElement;
352
353
  /**
353
354
  * @internal
@@ -338,6 +338,7 @@ export class AdvancedDynamicTexture extends DynamicTexture {
338
338
  // Invalidated rectangle which is the combination of all invalidated controls after they have been rotated into absolute position
339
339
  this._invalidatedRectangle = null;
340
340
  this._clearMeasure = new Measure(0, 0, 0, 0);
341
+ this._focusProperties = { index: 0, total: -1 };
341
342
  /**
342
343
  * @internal
343
344
  */
@@ -394,7 +395,15 @@ export class AdvancedDynamicTexture extends DynamicTexture {
394
395
  this._preKeyboardObserver = scene.onPreKeyboardObservable.add((info) => {
395
396
  // check if tab is pressed
396
397
  if (!this.disableTabNavigation && info.type === KeyboardEventTypes.KEYDOWN && info.event.code === "Tab") {
397
- this._focusNextElement(!info.event.shiftKey);
398
+ const forward = !info.event.shiftKey;
399
+ if ((forward && this._focusProperties.index === this._focusProperties.total - 1) ||
400
+ (!forward && this._focusProperties.index === 0 && this._focusProperties.total > 0)) {
401
+ this.focusedControl = null;
402
+ this._focusProperties.index = 0;
403
+ this._focusProperties.total = -1;
404
+ return;
405
+ }
406
+ this._focusNextElement(forward);
398
407
  info.event.preventDefault();
399
408
  return;
400
409
  }
@@ -951,21 +960,24 @@ export class AdvancedDynamicTexture extends DynamicTexture {
951
960
  // if tabIndex is 0, put it in the end of the list, otherwise sort by tabIndex
952
961
  return a.tabIndex === 0 ? 1 : b.tabIndex === 0 ? -1 : a.tabIndex - b.tabIndex;
953
962
  });
963
+ this._focusProperties.total = sortedTabbableControls.length;
954
964
  // if no control is focused, focus the first one
965
+ let nextIndex = -1;
955
966
  if (!this._focusedControl) {
956
- sortedTabbableControls[0].focus();
967
+ nextIndex = forward ? 0 : sortedTabbableControls.length - 1;
957
968
  }
958
969
  else {
959
970
  const currentIndex = sortedTabbableControls.indexOf(this._focusedControl);
960
- let nextIndex = currentIndex + (forward ? 1 : -1);
971
+ nextIndex = currentIndex + (forward ? 1 : -1);
961
972
  if (nextIndex < 0) {
962
973
  nextIndex = sortedTabbableControls.length - 1;
963
974
  }
964
975
  else if (nextIndex >= sortedTabbableControls.length) {
965
976
  nextIndex = 0;
966
977
  }
967
- sortedTabbableControls[nextIndex].focus();
968
978
  }
979
+ sortedTabbableControls[nextIndex].focus();
980
+ this._focusProperties.index = nextIndex;
969
981
  }
970
982
  /**
971
983
  * Register the clipboard Events onto the canvas