This commit is contained in:
Rene Haas
2022-08-26 11:00:11 +02:00
parent de6ce01816
commit 3ca039c92a
4 changed files with 13 additions and 8 deletions
@@ -15,7 +15,7 @@ import {
runEachAndClear,
} from 'support';
type DOMContentObserverCallback = (contentChangedTroughEvent: boolean) => any;
type DOMContentObserverCallback = (contentChangedThroughEvent: boolean) => any;
type DOMTargetObserverCallback = (targetChangedAttrs: string[], targetStyleChanged: boolean) => any;
@@ -33,11 +33,11 @@ import {
} from 'classnames';
import { getEnvironment } from 'environment';
import { getPlugins, scrollbarsHidingPluginName } from 'plugins';
import type { ScrollbarsHidingPluginInstance } from 'plugins/scrollbarsHidingPlugin';
import {
staticInitializationElement as generalStaticInitializationElement,
dynamicInitializationElement as generalDynamicInitializationElement,
} from 'initialization';
import type { ScrollbarsHidingPluginInstance } from 'plugins/scrollbarsHidingPlugin';
import type {
InitializationTarget,
InitializationTargetElement,
@@ -186,13 +186,13 @@ export const createStructureSetupObservers = (
updateFn({ _sizeChanged, _directionChanged: directionChanged });
};
const onContentMutation = (contentChangedTroughEvent: boolean, fromRecords?: true) => {
const onContentMutation = (contentChangedThroughEvent: boolean, fromRecords?: true) => {
const [, contentSizeChanged] = updateContentSizeCache();
const updateHints: Partial<StructureSetupUpdateHints> = {
_contentMutation: contentSizeChanged,
};
// if contentChangedTroughEvent is true its already debounced
const updateFn = contentChangedTroughEvent
// if contentChangedThroughEvent is true its already debounced
const updateFn = contentChangedThroughEvent
? structureSetupUpdate
: structureSetupUpdateWithDebouncedAdaptiveUpdateHints;
@@ -130,9 +130,14 @@ const assertCorrectDOMStructure = (targetType: TargetType, viewportIsTarget: boo
};
const createStructureSetupElementsProxy = (
target: InitializationTarget
target: InitializationTarget,
tabindex?: boolean
): StructureSetupElementsProxy => {
const [elements, appendElements, destroy] = createStructureSetupElements(target);
// simulate tabindex inheritance from host via mutation observer
if (tabindex) {
elements._viewport.setAttribute('tabindex', elements._target.getAttribute('tabindex')!);
}
appendElements();
return {
input: target,
@@ -1117,13 +1122,13 @@ describe('structureSetup.elements', () => {
const target = document.body.firstElementChild as HTMLElement;
target.focus();
const { elements } = createStructureSetupElementsProxy(target);
const { elements } = createStructureSetupElementsProxy(target, true);
expect(elements._viewport.getAttribute('tabindex')).toBe('-1');
expect(document.activeElement).toBe(elements._viewport);
elements._documentElm.dispatchEvent(new Event('keydown'));
expect(elements._viewport.getAttribute('tabindex')).toBe(null);
expect(elements._viewport.getAttribute('tabindex')).toBe('123');
});
});