@babylonjs/gui 7.13.0 → 7.13.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,7 +10,6 @@ import { Layer } from "@babylonjs/core/Layers/layer.js";
10
10
  import type { Scene } from "@babylonjs/core/scene.js";
11
11
  import { Container } from "./controls/container";
12
12
  import { Control } from "./controls/control";
13
- import type { IFocusableControl } from "./controls/focusableControl";
14
13
  import { Style } from "./style";
15
14
  import { Viewport } from "@babylonjs/core/Maths/math.viewport.js";
16
15
  /**
@@ -121,6 +120,11 @@ export declare class AdvancedDynamicTexture extends DynamicTexture {
121
120
  * Gets or sets a boolean indicating that the canvas must be reverted on Y when updating the texture
122
121
  */
123
122
  applyYInversionOnUpdate: boolean;
123
+ /**
124
+ * A boolean indicating whether or not the elements can be navigated to using the tab key.
125
+ * Defaults to false.
126
+ */
127
+ disableTabNavigation: boolean;
124
128
  /**
125
129
  * Gets or sets a number used to scale rendering size (2 means that the texture will be twice bigger).
126
130
  * Useful when you want more antialiasing
@@ -198,8 +202,8 @@ export declare class AdvancedDynamicTexture extends DynamicTexture {
198
202
  /**
199
203
  * Gets or sets the current focused control
200
204
  */
201
- get focusedControl(): Nullable<IFocusableControl>;
202
- set focusedControl(control: Nullable<IFocusableControl>);
205
+ get focusedControl(): Nullable<Control>;
206
+ set focusedControl(control: Nullable<Control>);
203
207
  /**
204
208
  * Gets or sets a boolean indicating if the texture must be rendered in background or foreground when in fullscreen mode
205
209
  */
@@ -344,6 +348,7 @@ export declare class AdvancedDynamicTexture extends DynamicTexture {
344
348
  private _translateToPicking;
345
349
  /** Attach to all scene events required to support pointer events */
346
350
  attach(): void;
351
+ private _focusNextElement;
347
352
  /**
348
353
  * @internal
349
354
  */
@@ -380,7 +385,7 @@ export declare class AdvancedDynamicTexture extends DynamicTexture {
380
385
  * Move the focus to a specific control
381
386
  * @param control defines the control which will receive the focus
382
387
  */
383
- moveFocusToControl(control: IFocusableControl): void;
388
+ moveFocusToControl(control: Control): void;
384
389
  private _manageFocus;
385
390
  private _attachPickingToSceneRender;
386
391
  private _attachToOnPointerOut;
@@ -316,6 +316,11 @@ export class AdvancedDynamicTexture extends DynamicTexture {
316
316
  * Gets or sets a boolean indicating that the canvas must be reverted on Y when updating the texture
317
317
  */
318
318
  this.applyYInversionOnUpdate = true;
319
+ /**
320
+ * A boolean indicating whether or not the elements can be navigated to using the tab key.
321
+ * Defaults to false.
322
+ */
323
+ this.disableTabNavigation = false;
319
324
  /**
320
325
  * If this is set, even when a control is pointer blocker, some events can still be passed through to the scene.
321
326
  * Options from values are PointerEventTypes
@@ -387,6 +392,12 @@ export class AdvancedDynamicTexture extends DynamicTexture {
387
392
  }
388
393
  });
389
394
  this._preKeyboardObserver = scene.onPreKeyboardObservable.add((info) => {
395
+ // check if tab is pressed
396
+ if (!this.disableTabNavigation && info.type === KeyboardEventTypes.KEYDOWN && info.event.code === "Tab") {
397
+ this._focusNextElement(!info.event.shiftKey);
398
+ info.event.preventDefault();
399
+ return;
400
+ }
390
401
  if (!this._focusedControl) {
391
402
  return;
392
403
  }
@@ -923,6 +934,39 @@ export class AdvancedDynamicTexture extends DynamicTexture {
923
934
  this._attachToOnPointerOut(scene);
924
935
  this._attachToOnBlur(scene);
925
936
  }
937
+ _focusNextElement(forward = true) {
938
+ // generate the order of tab-able controls
939
+ const sortedTabbableControls = [];
940
+ this.executeOnAllControls((control) => {
941
+ if (control.isFocusInvisible || !control.isVisible || control.tabIndex < 0) {
942
+ return;
943
+ }
944
+ sortedTabbableControls.push(control);
945
+ });
946
+ // if no control is tab-able, return
947
+ if (sortedTabbableControls.length === 0) {
948
+ return;
949
+ }
950
+ sortedTabbableControls.sort((a, b) => {
951
+ // if tabIndex is 0, put it in the end of the list, otherwise sort by tabIndex
952
+ return a.tabIndex === 0 ? 1 : b.tabIndex === 0 ? -1 : a.tabIndex - b.tabIndex;
953
+ });
954
+ // if no control is focused, focus the first one
955
+ if (!this._focusedControl) {
956
+ sortedTabbableControls[0].focus();
957
+ }
958
+ else {
959
+ const currentIndex = sortedTabbableControls.indexOf(this._focusedControl);
960
+ let nextIndex = currentIndex + (forward ? 1 : -1);
961
+ if (nextIndex < 0) {
962
+ nextIndex = sortedTabbableControls.length - 1;
963
+ }
964
+ else if (nextIndex >= sortedTabbableControls.length) {
965
+ nextIndex = 0;
966
+ }
967
+ sortedTabbableControls[nextIndex].focus();
968
+ }
969
+ }
926
970
  /**
927
971
  * Register the clipboard Events onto the canvas
928
972
  */