Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ interface EditorFactoryMixinType {

}

const ViewControllerWithMixin: ModuleType<ViewController & EditorFactoryMixinType> = EditorFactoryMixin(modules.ViewController) as any;
const ViewControllerWithMixin: ModuleType<ViewController & EditorFactoryMixinType> = EditorFactoryMixin(modules.ViewController);

export class EditorFactory extends ViewControllerWithMixin {
private _isFocusOverlay: any;
Expand Down
2 changes: 1 addition & 1 deletion packages/devextreme/js/__internal/pagination/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import type { RefObject } from '@ts/core/r1/types';
import { Widget } from '@ts/core/r1/widget';
import { createRef as infernoCreateRef } from 'inferno';

import { registerKeyboardAction } from '../../ui/shared/accessibility';
import type { EventCallback } from '../core/r1/event_callback';
import type { DisposeEffectReturn } from '../core/r1/utils/effect_return';
import { combineClasses } from '../core/r1/utils/render_utils';
import { registerKeyboardAction } from '../ui/shared/accessibility';
import {
LIGHT_MODE_CLASS,
PAGER_CLASS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { OptionChanged } from '@ts/core/widget/types';
import type { WidgetProperties } from '@ts/core/widget/widget';
import Widget from '@ts/core/widget/widget';
import Drawer from '@ts/ui/drawer/drawer';
import type { ActiveStateChangedEvent, ApplyPanelSizeEvent } from '@ts/ui/splitter_control';

const window = getWindow();
const ADAPTIVE_STATE_SCREEN_WIDTH = 573;
Expand All @@ -16,11 +17,6 @@ const FILE_MANAGER_ADAPTIVITY_DRAWER_PANEL_CLASS = 'dx-filemanager-adaptivity-dr
const DRAWER_PANEL_CONTENT_INITIAL = 'dx-drawer-panel-content-initial';
const DRAWER_PANEL_CONTENT_ADAPTIVE = 'dx-drawer-panel-content-adaptive';

interface PanelSize {
leftPanelWidth: string | number;
rightPanelWidth: string | number;
}

interface FileManagerAdaptivityControlOptions extends WidgetProperties {
drawerTemplate?: (container: dxElementWrapper | Element) => void;
contentTemplate?: (container: dxElementWrapper) => void;
Expand Down Expand Up @@ -87,7 +83,7 @@ class FileManagerAdaptivityControl extends Widget<FileManagerAdaptivityControlOp
this._checkAdaptiveState();
}

_onApplyPanelSize(e: PanelSize): void {
_onApplyPanelSize(e: ApplyPanelSizeEvent): void {
if (!hasWindow()) {
return;
}
Expand All @@ -100,9 +96,9 @@ class FileManagerAdaptivityControl extends Widget<FileManagerAdaptivityControlOp
this._setDrawerWidth(e.leftPanelWidth);
}

_onActiveStateChanged({ isActive }: { isActive: boolean }): void {
this._splitter?.disableSplitterCalculation(!isActive);
if (!isActive) {
_onActiveStateChanged(e: ActiveStateChangedEvent): void {
this._splitter?.disableSplitterCalculation(!e.isActive);
if (!e.isActive) {
this._splitter?.$element().css('left', 'auto');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '@js/core/utils/size';
import { hasWindow } from '@js/core/utils/window';
import type Gantt from '@ts/ui/gantt/ui.gantt';
import type { ApplyPanelSizeEvent } from '@ts/ui/splitter_control';

type Dimension = 'width' | 'height';

Expand Down Expand Up @@ -34,10 +35,9 @@ export class GanttSizeHelper {
this._gantt._setGanttViewOption(dimension, getter(this._gantt._$ganttView));
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
_getPanelsWidthByOption() {
_getPanelsWidthByOption(): ApplyPanelSizeEvent {
const ganttWidth = getWidth(this._gantt.$element());
const leftPanelWidth = this._gantt.option('taskListWidth');
const { taskListWidth: leftPanelWidth } = this._gantt.option();
// eslint-disable-next-line @typescript-eslint/init-declarations
let rightPanelWidth;
// @ts-expect-error ts-error
Expand All @@ -53,6 +53,7 @@ export class GanttSizeHelper {
// @ts-expect-error ts-error
rightPanelWidth = `${100 - parseInt(leftPanelWidth.replace('%', ''), 10)}%`;
}
// @ts-expect-error ts-error
return { leftPanelWidth, rightPanelWidth };
}

Expand Down Expand Up @@ -85,7 +86,7 @@ export class GanttSizeHelper {
}
}

setInnerElementsWidth(widths?): void {
setInnerElementsWidth(widths?: ApplyPanelSizeEvent): void {
if (!hasWindow()) {
return;
}
Expand All @@ -96,8 +97,8 @@ export class GanttSizeHelper {
this._setTreeListDimension('width', 0);
this._setGanttViewDimension('width', 0);
}
this._setTreeListDimension('width', widths.leftPanelWidth);
this._setGanttViewDimension('width', widths.rightPanelWidth);
this._setTreeListDimension('width', widths?.leftPanelWidth);
this._setGanttViewDimension('width', widths?.rightPanelWidth);
if (takeWithFromOption) {
this._gantt._splitter?._setSplitterPositionLeft();
}
Expand Down
6 changes: 2 additions & 4 deletions packages/devextreme/js/__internal/ui/gantt/ui.gantt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,8 @@ class Gantt extends Widget<Properties> {
this._sizeHelper?.onApplyPanelSize(e);
},
});
this._splitter.option(
'initialLeftPanelWidth',
this.option('taskListWidth'),
);
const { taskListWidth } = this.option();
this._splitter.option('initialLeftPanelWidth', taskListWidth);
}

_renderBars(): void {
Expand Down
270 changes: 270 additions & 0 deletions packages/devextreme/js/__internal/ui/shared/accessibility.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
import eventsEngine from '@js/common/core/events/core/events_engine';
import { normalizeKeyName } from '@js/common/core/events/utils/index';
import domAdapter from '@js/core/dom_adapter';
import type { dxElementWrapper } from '@js/core/renderer';
import $ from '@js/core/renderer';
import { noop } from '@js/core/utils/common';
import { extend } from '@js/core/utils/extend';

const FOCUS_STATE_CLASS = 'dx-state-focused';
const FOCUS_DISABLED_CLASS = 'dx-cell-focus-disabled';
const FOCUSED_ROW_SELECTOR = '.dx-row-focused';
const GRID_ROW_SELECTOR = '.dx-datagrid-rowsview .dx-row';
const GRID_CELL_SELECTOR = `${GRID_ROW_SELECTOR} > td`;
const TREELIST_ROW_SELECTOR = '.dx-treelist-rowsview .dx-row';
const TREELIST_CELL_SELECTOR = `${TREELIST_ROW_SELECTOR} > td`;
const viewItemSelectorMap = {
groupPanel: ['.dx-datagrid-group-panel .dx-group-panel-item[tabindex]'],
columnHeaders: ['.dx-datagrid-headers .dx-header-row > td.dx-datagrid-action', '.dx-treelist-headers .dx-header-row > td.dx-treelist-action'],
filterRow: [
'.dx-datagrid-headers .dx-datagrid-filter-row .dx-editor-cell .dx-texteditor-input',
'.dx-treelist-headers .dx-treelist-filter-row .dx-editor-cell .dx-texteditor-input',
],
rowsView: [
`${FOCUSED_ROW_SELECTOR}`,
`${GRID_ROW_SELECTOR}[tabindex]`,
`${GRID_CELL_SELECTOR}[tabindex]`,
`${GRID_CELL_SELECTOR}`,
`${TREELIST_ROW_SELECTOR}[tabindex]`,
`${TREELIST_CELL_SELECTOR}[tabindex]`,
`${TREELIST_CELL_SELECTOR}`,
],
footer: ['.dx-datagrid-total-footer .dx-datagrid-summary-item', '.dx-treelist-total-footer .dx-treelist-summary-item'],
filterPanel: ['.dx-datagrid-filter-panel .dx-icon-filter', '.dx-treelist-filter-panel .dx-icon-filter'],
pager: ['.dx-datagrid-pager [tabindex]', '.dx-treelist-pager [tabindex]'],
};

let isMouseDown = false;
let isHiddenFocusing = false;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let focusedElementInfo: any = null;
let needToSkipFocusin = false;

function getActiveAccessibleElements(ariaLabel?: string, viewElement?): dxElementWrapper {
const $viewElement = $(viewElement);
let $activeElements: dxElementWrapper = $();

if (ariaLabel) {
const escapedAriaLabel = ariaLabel?.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
$activeElements = $viewElement.find(`[aria-label="${escapedAriaLabel}"][tabindex]`);
} else {
$activeElements = $viewElement.find('[tabindex]');
}

return $activeElements;
}

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function saveFocusedElementInfo(target, instance): void {
const $target = $(target);
const ariaLabel = $target.attr('aria-label');
const $activeElements = getActiveAccessibleElements(ariaLabel, instance.element());
const targetIndex = $activeElements.index($target);

focusedElementInfo = extend(
{},
{ ariaLabel, index: targetIndex },
{ viewInstance: instance },
);
}

function fireKeyDownEvent(instance, event, executeAction): boolean {
const args = {
event,
handled: false,
};

if (executeAction) {
executeAction(args);
} else {
instance._createActionByOption('onKeyDown')(args);
}

return args.handled;
}

function findFocusedViewElement(
instanceRootDomNode,
viewSelectors,
element,
// @ts-expect-error ts-error
): dxElementWrapper | undefined {
const root = instanceRootDomNode ?? element?.getRootNode() ?? domAdapter.getDocument();

if (!root) {
return;
}

const $root = $(root);

// eslint-disable-next-line no-restricted-syntax,guard-for-in
for (const index in viewSelectors) {
const selector = viewSelectors[index];
const $focusViewElement = $root.find(selector).first();

if ($focusViewElement.length) {
// eslint-disable-next-line consistent-return
return $focusViewElement;
}
}
}

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function selectView(viewName: string, instance, event): void {
const keyName = normalizeKeyName(event);

if (event.ctrlKey && (keyName === 'upArrow' || keyName === 'downArrow')) {
const viewNames = Object.keys(viewItemSelectorMap);
let viewItemIndex = viewNames.indexOf(viewName);

const instanceRootDomNode = instance?.component?.element?.();

while (viewItemIndex >= 0 && viewItemIndex < viewNames.length) {
viewItemIndex += keyName === 'upArrow' ? -1 : 1;
// eslint-disable-next-line @typescript-eslint/no-shadow
const viewName = viewNames[viewItemIndex];
const viewSelectors = viewItemSelectorMap[viewName];
const $focusViewElement = findFocusedViewElement(
instanceRootDomNode,
viewSelectors,
event.target,
);
if ($focusViewElement?.length) {
$focusViewElement.attr('tabindex', instance.option('tabindex') || 0);
// @ts-expect-error ts-error
eventsEngine.trigger($focusViewElement, 'focus');
$focusViewElement.removeClass(FOCUS_DISABLED_CLASS);
break;
}
}
}
}

function processKeyDown(viewName, instance, event, action, $mainElement, executeKeyDown): void {
const isHandled = fireKeyDownEvent(instance, event.originalEvent, executeKeyDown);
if (isHandled) {
return;
}

const keyName = normalizeKeyName(event);

if (keyName === 'enter' || keyName === 'space') {
saveFocusedElementInfo(event.target, instance);
action?.({ event });
} else if (keyName === 'tab') {
$mainElement.addClass(FOCUS_STATE_CLASS);
} else {
selectView(viewName, instance, event);
}
}

function onDocumentVisibilityChange(): void {
const focusedElement = domAdapter.getActiveElement();

needToSkipFocusin = focusedElement && !focusedElement.closest(`.${FOCUS_STATE_CLASS}`);
}

export function subscribeVisibilityChange(): void {
eventsEngine.on(domAdapter.getDocument(), 'visibilitychange', onDocumentVisibilityChange);
}

export function unsubscribeVisibilityChange(): void {
eventsEngine.off(domAdapter.getDocument(), 'visibilitychange', onDocumentVisibilityChange);
}

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function hiddenFocus(element, preventScroll?: boolean): void {
isHiddenFocusing = true;
element.focus({ preventScroll });
isHiddenFocusing = false;
}

export function registerKeyboardAction(
viewName: string,
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
instance,
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
$element,
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
selector,
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
action,
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
executeKeyDown?,
): () => void {
const { useLegacyKeyboardNavigation } = instance.option();
if (useLegacyKeyboardNavigation) {
return noop;
}

const getMainElement = (): dxElementWrapper => $(instance.element());
const keyDownHandler = (e): void => processKeyDown(
viewName,
instance,
e,
action,
getMainElement(),
executeKeyDown,
);
const mouseDownHandler = (): void => {
isMouseDown = true;
getMainElement().removeClass(FOCUS_STATE_CLASS);
};
const focusinHandler = (): void => {
if (needToSkipFocusin) {
needToSkipFocusin = false;
return;
}

const needShowOverlay = !isMouseDown && !isHiddenFocusing;
if (needShowOverlay) {
getMainElement().addClass(FOCUS_STATE_CLASS);
}
isMouseDown = false;
};
const mouseUpHandler = (): void => {
isMouseDown = false;
};

eventsEngine.on($element, 'keydown', selector, keyDownHandler);
eventsEngine.on($element, 'mousedown', selector, mouseDownHandler);
eventsEngine.on($element, 'focusin', selector, focusinHandler);
eventsEngine.on($element, 'mouseup contextmenu', selector, mouseUpHandler);
return (): void => {
// @ts-expect-error ts-error
eventsEngine.off($element, 'keydown', selector, keyDownHandler);
// @ts-expect-error ts-error
eventsEngine.off($element, 'mousedown', selector, mouseDownHandler);
// @ts-expect-error ts-error
eventsEngine.off($element, 'focusin', selector, focusinHandler);
// @ts-expect-error ts-error
eventsEngine.off($element, 'mouseup contextmenu', selector, mouseUpHandler);
};
}

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function restoreFocus(instance): void {
if (!instance.option('useLegacyKeyboardNavigation') && focusedElementInfo) {
const { viewInstance } = focusedElementInfo;
if (viewInstance) {
const $activeElements = getActiveAccessibleElements(
focusedElementInfo.ariaLabel,
viewInstance.element(),
);
const $targetElement = $activeElements.eq(focusedElementInfo.index);

focusedElementInfo = null;

// @ts-expect-error ts-error
eventsEngine.trigger($targetElement, 'focus');
}
}
}

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function setTabIndex(instance, $element: dxElementWrapper): void {
const { useLegacyKeyboardNavigation } = instance.option();
if (!useLegacyKeyboardNavigation) {
$element.attr('tabindex', instance.option('tabindex') || 0);
}
}
Loading
Loading