Skip to content

Commit e39f084

Browse files
authored
Scheduler - A11y - Don't hide tooltip on item delete (#33410)
1 parent 37ec0b8 commit e39f084

16 files changed

Lines changed: 763 additions & 358 deletions

File tree

3.25 KB
Loading

packages/devextreme/js/__internal/scheduler/__tests__/__mock__/m_mock_scheduler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,8 @@ export const setupSchedulerTestEnvironment = ({
7070

7171
return defaultRect;
7272
});
73+
74+
Element.prototype.getClientRects = jest.fn(function (): DOMRectList {
75+
return [Element.prototype.getBoundingClientRect.call(this)] as unknown as DOMRectList;
76+
});
7377
};
Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
1+
import type { dxElementWrapper } from '@js/core/renderer';
2+
import $ from '@js/core/renderer';
3+
import type dxTooltip from '@js/ui/tooltip';
14
import { within } from '@testing-library/dom';
25

3-
const TOOLTIP_WRAPPER_SELECTOR = '.dx-overlay-wrapper.dx-scheduler-appointment-tooltip-wrapper';
6+
const TOOLTIP_WRAPPER_SELECTOR = `
7+
.dx-overlay-wrapper.dx-scheduler-overlay-panel,
8+
.dx-overlay-wrapper.dx-scheduler-appointment-tooltip-wrapper
9+
`;
410

511
export class TooltipModel {
6-
private get element(): HTMLElement | null {
12+
get element(): HTMLElement | null {
713
return document.querySelector<HTMLElement>(TOOLTIP_WRAPPER_SELECTOR);
814
}
915

16+
get dxTooltip(): dxTooltip {
17+
// @ts-expect-error
18+
return $('.dx-tooltip.dx-widget').dxTooltip('instance') as dxTooltip;
19+
}
20+
21+
get target(): Element | null {
22+
const $target = this.dxTooltip.option('target') as unknown as dxElementWrapper;
23+
return $target?.get(0) ?? null;
24+
}
25+
1026
isVisible(): boolean {
1127
return this.element !== null;
1228
}
@@ -15,24 +31,35 @@ export class TooltipModel {
1531
return this.element?.querySelector('.dx-scrollable .dx-scrollview-content') ?? null;
1632
}
1733

18-
getDeleteButton(index = 0): HTMLElement {
19-
const tooltip = this.element;
20-
const buttons = tooltip
21-
? within(tooltip).queryAllByRole('button').filter((btn) => btn.classList.contains('dx-tooltip-appointment-item-delete-button'))
34+
getDeleteButtons(): HTMLElement[] {
35+
return this.element
36+
? within(this.element).queryAllByRole('button').filter(
37+
(btn) => btn.classList.contains('dx-tooltip-appointment-item-delete-button'),
38+
)
2239
: [];
40+
}
2341

24-
if (buttons.length === 0) {
42+
getDeleteButton(index = 0): HTMLElement {
43+
const buttons = this.getDeleteButtons();
44+
45+
if (buttons.length <= index) {
2546
throw new Error('Tooltip delete button not found');
2647
}
2748

2849
return buttons[index];
2950
}
3051

31-
getAppointmentItem(index = 0): HTMLElement | null {
32-
const tooltip = this.element;
33-
if (!tooltip) {
34-
return null;
52+
getAppointmentItems(): HTMLElement[] {
53+
return this.element ? within(this.element).queryAllByRole('option') : [];
54+
}
55+
56+
getAppointmentItem(index = 0): HTMLElement {
57+
const items = this.getAppointmentItems();
58+
59+
if (items.length <= index) {
60+
throw new Error('Tooltip appointment item not found');
3561
}
36-
return within(tooltip).queryAllByRole('option')[index] ?? null;
62+
63+
return items[index];
3764
}
3865
}

0 commit comments

Comments
 (0)