Skip to content

Commit bfe8fe7

Browse files
Fixed focus on Dropdown Server Side
1 parent 1cf7728 commit bfe8fe7

File tree

4 files changed

+67
-16
lines changed

4 files changed

+67
-16
lines changed

src/scripts/OSFramework/OSUI/Constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace OSFramework.OSUI.Constants {
66
export const A11YAttributes = {
77
Aria: {
88
Atomic: 'aria-atomic',
9+
Modal: 'aria-modal',
910
Busy: 'aria-busy',
1011
Controls: 'aria-controls',
1112
Describedby: 'aria-describedby',
@@ -43,6 +44,7 @@ namespace OSFramework.OSUI.Constants {
4344
AttrName: 'role',
4445
Button: 'button',
4546
Complementary: 'complementary',
47+
Dialog: 'dialog',
4648
Listbox: 'listbox',
4749
Menu: 'menu',
4850
MenuItem: 'menuitem',

src/scripts/OSFramework/OSUI/Feature/Balloon/Balloon.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,13 @@ namespace OSFramework.OSUI.Feature.Balloon {
210210
Helper.Dom.Attribute.Set(this.featureElem, Constants.A11YAttributes.Aria.Hidden, (!this.isOpen).toString());
211211

212212
if (this.featureOptions.focusOptions.useFocus !== false) {
213-
// Will handle the tabindex value of the elements inside pattern
214-
Helper.A11Y.SetElementsTabIndex(this.isOpen, this._focusTrapInstance.focusableElements);
213+
if (Helper.DeviceInfo.IsMobileDevice === false) {
214+
// Will handle the tabindex value of the elements inside pattern
215+
Helper.A11Y.SetElementsTabIndex(this.isOpen, this._focusTrapInstance.focusableElements);
216+
} else {
217+
Helper.A11Y.RoleDialog(this.featureElem);
218+
Helper.A11Y.AriaModalTrue(this.featureElem);
219+
}
215220

216221
Helper.Dom.Attribute.Set(
217222
this.featureElem,
@@ -310,7 +315,7 @@ namespace OSFramework.OSUI.Feature.Balloon {
310315
this._setA11YProperties();
311316

312317
if (this.isOpen) {
313-
if (this.featureOptions.focusOptions.useFocus !== false) {
318+
if (this.featureOptions.focusOptions.useFocus !== false && Helper.DeviceInfo.IsMobileDevice === false) {
314319
// Handle focus trap logic
315320
this._focusManagerInstance.storeLastFocusedElement();
316321
this._focusTrapInstance.enableForA11y();
@@ -323,15 +328,17 @@ namespace OSFramework.OSUI.Feature.Balloon {
323328
this._manageFocusInsideBalloon(arrowKeyPressed);
324329
}
325330
} else if (this.featureOptions.focusOptions.useFocus !== false) {
326-
// Handle focus trap logic
327-
this._focusTrapInstance.disableForA11y();
328-
// Focus on last element clicked. Async to avoid conflict with closing animation
329-
Helper.AsyncInvocation(() => {
330-
this.featureElem.blur();
331-
if (isBodyClick === false) {
332-
this._focusManagerInstance.setFocusToStoredElement();
333-
}
334-
});
331+
if (Helper.DeviceInfo.IsMobileDevice === false) {
332+
// Handle focus trap logic
333+
this._focusTrapInstance.disableForA11y();
334+
// Focus on last element clicked. Async to avoid conflict with closing animation
335+
Helper.AsyncInvocation(() => {
336+
this.featureElem.blur();
337+
if (isBodyClick === false) {
338+
this._focusManagerInstance.setFocusToStoredElement();
339+
}
340+
});
341+
}
335342

336343
// Unset focus attributes
337344
this._focusableBalloonElements = undefined;
@@ -366,7 +373,7 @@ namespace OSFramework.OSUI.Feature.Balloon {
366373
this._setEventListeners();
367374
this.setFloatingConfigs();
368375

369-
if (this.featureOptions.focusOptions.useFocus !== false) {
376+
if (this.featureOptions.focusOptions.useFocus !== false && Helper.DeviceInfo.IsMobileDevice === false) {
370377
this._handleFocusBehavior();
371378
}
372379

src/scripts/OSFramework/OSUI/Helper/ManageAccessibility.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,28 @@ namespace OSFramework.OSUI.Helper {
298298
);
299299
}
300300

301+
/**
302+
* Method that will disable the aria-modal
303+
*
304+
* @param {HTMLElement} element Target element to receive the value atributte
305+
* @returns
306+
* @memberof OSFramework.Helper.A11Y
307+
*/
308+
public static AriaModalFalse(element: HTMLElement): void {
309+
Dom.Attribute.Set(element, Constants.A11YAttributes.Aria.Modal, Constants.A11YAttributes.States.False);
310+
}
311+
312+
/**
313+
* Method that will enable the aria-modal
314+
*
315+
* @param {HTMLElement} element Target element to receive the value atributte
316+
* @returns
317+
* @memberof OSFramework.Helper.A11Y
318+
*/
319+
public static AriaModalTrue(element: HTMLElement): void {
320+
Dom.Attribute.Set(element, Constants.A11YAttributes.Aria.Modal, Constants.A11YAttributes.States.True);
321+
}
322+
301323
/**
302324
* Method that will set the aria-selected to false
303325
*
@@ -411,6 +433,21 @@ namespace OSFramework.OSUI.Helper {
411433
);
412434
}
413435

436+
/**
437+
* Method that will set the Dialog role
438+
*
439+
* @static
440+
* @param {HTMLElement} element
441+
* @memberof OSFramework.Helper.A11Y
442+
*/
443+
public static RoleDialog(element: HTMLElement): void {
444+
Dom.Attribute.Set(
445+
element,
446+
Constants.A11YAttributes.Role.AttrName,
447+
Constants.A11YAttributes.Role.Dialog
448+
);
449+
}
450+
414451
/**
415452
* Method that will set the list box role
416453
*

src/scripts/OSFramework/OSUI/Pattern/Dropdown/ServerSide/DropdownServerSide.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,9 +611,14 @@ namespace OSFramework.OSUI.Patterns.Dropdown.ServerSide {
611611

612612
// Check if inputSearch exist
613613
if (this._balloonSearchInputElement) {
614-
this._balloonSearchInputElement.focus();
614+
// This is the time needed in mobile devices to draw the input before focusing it
615+
OSFramework.OSUI.Helper.ApplySetTimeOut(() => {
616+
this._balloonSearchInputElement.focus();
617+
}, 20);
615618
} else {
616-
this._balloonOptionsWrapperElement.focus();
619+
OSFramework.OSUI.Helper.ApplySetTimeOut(() => {
620+
this._balloonOptionsWrapperElement.focus();
621+
}, 20);
617622
}
618623
} else {
619624
// Remove IsOpened Class
@@ -927,7 +932,7 @@ namespace OSFramework.OSUI.Patterns.Dropdown.ServerSide {
927932
} else {
928933
// Set focus options to pass to the Balloon feature
929934
const _focusOptions = {
930-
elemToFocusOnOpen: this._selectValuesWrapper,
935+
elemToFocusOnOpen: this._balloonElem,
931936
useFocus: true,
932937
focusTrapParams: {
933938
focusBottomCallback: this.close.bind(this),

0 commit comments

Comments
 (0)