krl-alfred 2.25.5 → 2.25.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Accordion/Accordion.styled.d.ts +2 -1
- package/dist/components/Accordion/Accordion.styled.js +4 -3
- package/dist/components/Accordion/Accordion.test.d.ts +1 -0
- package/dist/components/Accordion/Accordion.test.js +263 -0
- package/dist/components/Accordion/AccordionItem.d.ts +11 -9
- package/dist/components/Accordion/AccordionItem.js +85 -15
- package/dist/components/CouponCode/CouponCode.js +1 -1
- package/dist/components/Modal/Modal.js +11 -2
- package/dist/components/Modal/Modal.styled.js +1 -1
- package/dist/components/Modal/Modal.test.js +147 -4
- package/dist/components/Modal/core/modalFocus.d.ts +3 -0
- package/dist/components/Modal/core/modalFocus.js +106 -0
- package/dist/i18n/locales/english.json +1 -0
- package/dist/i18n/locales/turkish.json +1 -0
- package/package.json +1 -1
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { AccordionStyledProps } from "./props";
|
|
3
|
+
export declare const ACCORDION_PANEL_TRANSITION_MS = 300;
|
|
3
4
|
export declare const AccordionStyled: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "$size"> & AccordionStyledProps, never> & Partial<Pick<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "$size"> & AccordionStyledProps, never>>> & string;
|
|
4
5
|
export declare const AccordionTitle: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>, "$size"> & AccordionStyledProps, never> & Partial<Pick<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>, "$size"> & AccordionStyledProps, never>>> & string;
|
|
5
6
|
export declare const Wrapper: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "$size"> & AccordionStyledProps, never> & Partial<Pick<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "$size"> & AccordionStyledProps, never>>> & string;
|
|
6
7
|
export declare const Item: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "$size"> & AccordionStyledProps, never> & Partial<Pick<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "$size"> & AccordionStyledProps, never>>> & string;
|
|
7
|
-
export declare const ItemTitle: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").
|
|
8
|
+
export declare const ItemTitle: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "$size"> & AccordionStyledProps, never> & Partial<Pick<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "$size"> & AccordionStyledProps, never>>> & string;
|
|
8
9
|
export declare const ItemContent: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "$size"> & AccordionStyledProps, never> & Partial<Pick<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "$size"> & AccordionStyledProps, never>>> & string;
|
|
9
10
|
export declare const Footer: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "$size"> & AccordionStyledProps, never> & Partial<Pick<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "$size"> & AccordionStyledProps, never>>> & string;
|
|
@@ -7,14 +7,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
7
7
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
8
|
};
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.Footer = exports.ItemContent = exports.ItemTitle = exports.Item = exports.Wrapper = exports.AccordionTitle = exports.AccordionStyled = void 0;
|
|
10
|
+
exports.Footer = exports.ItemContent = exports.ItemTitle = exports.Item = exports.Wrapper = exports.AccordionTitle = exports.AccordionStyled = exports.ACCORDION_PANEL_TRANSITION_MS = void 0;
|
|
11
11
|
var styled_components_1 = __importDefault(require("styled-components"));
|
|
12
12
|
var devices_1 = require("../../constants/devices");
|
|
13
|
+
exports.ACCORDION_PANEL_TRANSITION_MS = 300;
|
|
13
14
|
exports.AccordionStyled = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: block;\n"], ["\n display: block;\n"])));
|
|
14
15
|
exports.AccordionTitle = styled_components_1.default.h1(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n margin-bottom: 1.5rem;\n margin-top: 0;\n font : ", ";\n\n @media only screen and ", " {\n font : var(--title-bold-16-19);\n }\n"], ["\n margin-bottom: 1.5rem;\n margin-top: 0;\n font : ", ";\n\n @media only screen and ", " {\n font : var(--title-bold-16-19);\n }\n"])), function (props) { return props.$size === "large" ? "var(--headline-bold-18-22)" : "var(--title-bold-16-19)"; }, devices_1.devices.lg);
|
|
15
16
|
exports.Wrapper = styled_components_1.default.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n\n"], ["\n\n"])));
|
|
16
17
|
exports.Item = styled_components_1.default.div(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n &:not(:nth-child(1)) {\n margin-top: 1.5rem;\n }\n"], ["\n &:not(:nth-child(1)) {\n margin-top: 1.5rem;\n }\n"])));
|
|
17
|
-
exports.ItemTitle = styled_components_1.default.
|
|
18
|
-
exports.ItemContent = styled_components_1.default.div(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n transition:
|
|
18
|
+
exports.ItemTitle = styled_components_1.default.button(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n display: flex;\n align-items: center;\n justify-content: space-between;\n width: 100%;\n margin: 0;\n padding: 0;\n border: 0;\n background: transparent;\n color: inherit;\n text-align: left;\n appearance: none;\n cursor: pointer;\n font : ", ";\n\n &:focus-visible {\n outline: 2px solid var(--primary);\n outline-offset: 2px;\n }\n >div{\n position: relative;\n &:last-child{\n margin-left: 1rem;\n > div{\n transition: all .3s ease;\n &:first-child{\n opacity: 0;\n }\n &:last-child{\n position: absolute;\n inset: 0;\n opacity: 1;\n }\n }\n }\n }\n \n &:is(.active){\n >div{\n &:last-child{\n > div{\n &:first-child{\n opacity: 1;\n }\n &:last-child{\n transform: rotate(90deg);\n opacity: 0;\n }\n }\n }\n }\n }\n @media only screen and ", " {\n font : var(--body-bold-14-17);\n }\n"], ["\n display: flex;\n align-items: center;\n justify-content: space-between;\n width: 100%;\n margin: 0;\n padding: 0;\n border: 0;\n background: transparent;\n color: inherit;\n text-align: left;\n appearance: none;\n cursor: pointer;\n font : ", ";\n\n &:focus-visible {\n outline: 2px solid var(--primary);\n outline-offset: 2px;\n }\n >div{\n position: relative;\n &:last-child{\n margin-left: 1rem;\n > div{\n transition: all .3s ease;\n &:first-child{\n opacity: 0;\n }\n &:last-child{\n position: absolute;\n inset: 0;\n opacity: 1;\n }\n }\n }\n }\n \n &:is(.active){\n >div{\n &:last-child{\n > div{\n &:first-child{\n opacity: 1;\n }\n &:last-child{\n transform: rotate(90deg);\n opacity: 0;\n }\n }\n }\n }\n }\n @media only screen and ", " {\n font : var(--body-bold-14-17);\n }\n"])), function (props) { return props.$size === "large" ? "var(--title-bold-16-19)" : "var(--body-bold-14-17)"; }, devices_1.devices.lg);
|
|
19
|
+
exports.ItemContent = styled_components_1.default.div(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n transition: height ", "ms ease;\n overflow: hidden;\n position: relative;\n font : ", ";\n @media only screen and ", " {\n font : var(--body-regular-14-17);\n }\n > div{\n padding: 1rem 2rem 0 0;\n a{\n color : var(--primary);\n &:hover , :focus , :active {\n color: var(--primary-hover);\n }\n }\n }\n"], ["\n transition: height ", "ms ease;\n overflow: hidden;\n position: relative;\n font : ", ";\n @media only screen and ", " {\n font : var(--body-regular-14-17);\n }\n > div{\n padding: 1rem 2rem 0 0;\n a{\n color : var(--primary);\n &:hover , :focus , :active {\n color: var(--primary-hover);\n }\n }\n }\n"])), exports.ACCORDION_PANEL_TRANSITION_MS, function (props) { return props.$size === "large" ? "var(--title-regular-16-19)" : "var(--body-regular-14-17)"; }, devices_1.devices.lg);
|
|
19
20
|
exports.Footer = styled_components_1.default.div(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n box-sizing: border-box;\n display: block;\n margin-top: 1.5rem!important;\n font : var(--body-bold-14-17);\n"], ["\n box-sizing: border-box;\n display: block;\n margin-top: 1.5rem!important;\n font : var(--body-bold-14-17);\n"])));
|
|
20
21
|
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
54
|
+
var react_1 = require("react");
|
|
55
|
+
var react_2 = require("@testing-library/react");
|
|
56
|
+
var user_event_1 = __importDefault(require("@testing-library/user-event"));
|
|
57
|
+
var Accordion_1 = __importDefault(require("./Accordion"));
|
|
58
|
+
var items = [
|
|
59
|
+
{
|
|
60
|
+
question: 'İade nasıl yapılır?',
|
|
61
|
+
answer: 'İade için <a href="/orders">siparişlerim</a> sayfasına git.',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
question: 'Hasar güvencesi nedir?',
|
|
65
|
+
answer: 'Basit çizikler hasardan sayılmaz.',
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
var ResizeObserverMock = /** @class */ (function () {
|
|
69
|
+
function ResizeObserverMock(callback) {
|
|
70
|
+
this.target = null;
|
|
71
|
+
this.disconnect = jest.fn();
|
|
72
|
+
this.callback = callback;
|
|
73
|
+
ResizeObserverMock.instances.push(this);
|
|
74
|
+
}
|
|
75
|
+
ResizeObserverMock.prototype.observe = function (target) {
|
|
76
|
+
this.target = target;
|
|
77
|
+
};
|
|
78
|
+
ResizeObserverMock.prototype.unobserve = function () { };
|
|
79
|
+
ResizeObserverMock.prototype.emit = function (blockSize) {
|
|
80
|
+
var _this = this;
|
|
81
|
+
(0, react_1.act)(function () {
|
|
82
|
+
_this.callback([
|
|
83
|
+
{
|
|
84
|
+
target: _this.target,
|
|
85
|
+
borderBoxSize: [{ blockSize: blockSize, inlineSize: 100 }],
|
|
86
|
+
},
|
|
87
|
+
], _this);
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
ResizeObserverMock.instances = [];
|
|
91
|
+
return ResizeObserverMock;
|
|
92
|
+
}());
|
|
93
|
+
var renderAccordion = function (props) {
|
|
94
|
+
if (props === void 0) { props = {}; }
|
|
95
|
+
return (0, react_2.render)((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("input", { "aria-label": "\u00F6nce" }), (0, jsx_runtime_1.jsx)(Accordion_1.default, __assign({ data: items }, props)), (0, jsx_runtime_1.jsx)("input", { "aria-label": "sonra" })] }));
|
|
96
|
+
};
|
|
97
|
+
var questions = function () { return react_2.screen.getAllByRole('button', { name: /nasıl|nedir/ }); };
|
|
98
|
+
describe('Accordion', function () {
|
|
99
|
+
beforeEach(function () {
|
|
100
|
+
ResizeObserverMock.instances = [];
|
|
101
|
+
window.ResizeObserver = ResizeObserverMock;
|
|
102
|
+
jest.spyOn(window, 'requestAnimationFrame').mockImplementation(function (callback) {
|
|
103
|
+
callback(0);
|
|
104
|
+
return 1;
|
|
105
|
+
});
|
|
106
|
+
jest.spyOn(window, 'cancelAnimationFrame').mockImplementation(function () { return undefined; });
|
|
107
|
+
});
|
|
108
|
+
afterEach(function () {
|
|
109
|
+
jest.restoreAllMocks();
|
|
110
|
+
});
|
|
111
|
+
it('exposes each question as a button in DOM order', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
112
|
+
var user, _a, first, second;
|
|
113
|
+
return __generator(this, function (_b) {
|
|
114
|
+
switch (_b.label) {
|
|
115
|
+
case 0:
|
|
116
|
+
user = user_event_1.default.setup();
|
|
117
|
+
renderAccordion();
|
|
118
|
+
_a = questions(), first = _a[0], second = _a[1];
|
|
119
|
+
expect(first).toHaveAttribute('type', 'button');
|
|
120
|
+
expect(first).toHaveAccessibleName('İade nasıl yapılır?');
|
|
121
|
+
expect(second).toHaveAccessibleName('Hasar güvencesi nedir?');
|
|
122
|
+
expect(first).toHaveAttribute('aria-expanded', 'false');
|
|
123
|
+
expect(first).toHaveAttribute('aria-controls');
|
|
124
|
+
return [4 /*yield*/, user.tab()];
|
|
125
|
+
case 1:
|
|
126
|
+
_b.sent();
|
|
127
|
+
expect(react_2.screen.getByRole('textbox', { name: 'önce' })).toHaveFocus();
|
|
128
|
+
return [4 /*yield*/, user.tab()];
|
|
129
|
+
case 2:
|
|
130
|
+
_b.sent();
|
|
131
|
+
expect(first).toHaveFocus();
|
|
132
|
+
return [4 /*yield*/, user.tab()];
|
|
133
|
+
case 3:
|
|
134
|
+
_b.sent();
|
|
135
|
+
expect(second).toHaveFocus();
|
|
136
|
+
return [4 /*yield*/, user.tab()];
|
|
137
|
+
case 4:
|
|
138
|
+
_b.sent();
|
|
139
|
+
expect(react_2.screen.getByRole('textbox', { name: 'sonra' })).toHaveFocus();
|
|
140
|
+
return [2 /*return*/];
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}); });
|
|
144
|
+
it('toggles with click, Enter, and Space and keeps a single item open', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
145
|
+
var user, _a, first, second;
|
|
146
|
+
return __generator(this, function (_b) {
|
|
147
|
+
switch (_b.label) {
|
|
148
|
+
case 0:
|
|
149
|
+
user = user_event_1.default.setup();
|
|
150
|
+
renderAccordion();
|
|
151
|
+
_a = questions(), first = _a[0], second = _a[1];
|
|
152
|
+
return [4 /*yield*/, user.click(first)];
|
|
153
|
+
case 1:
|
|
154
|
+
_b.sent();
|
|
155
|
+
expect(first).toHaveAttribute('aria-expanded', 'true');
|
|
156
|
+
expect(first).toHaveFocus();
|
|
157
|
+
expect(react_2.screen.getByRole('region', { name: 'İade nasıl yapılır?' })).toHaveTextContent('siparişlerim');
|
|
158
|
+
return [4 /*yield*/, user.click(second)];
|
|
159
|
+
case 2:
|
|
160
|
+
_b.sent();
|
|
161
|
+
expect(first).toHaveAttribute('aria-expanded', 'false');
|
|
162
|
+
expect(second).toHaveAttribute('aria-expanded', 'true');
|
|
163
|
+
second.focus();
|
|
164
|
+
return [4 /*yield*/, user.keyboard('{Enter}')];
|
|
165
|
+
case 3:
|
|
166
|
+
_b.sent();
|
|
167
|
+
expect(second).toHaveAttribute('aria-expanded', 'false');
|
|
168
|
+
return [4 /*yield*/, user.keyboard(' ')];
|
|
169
|
+
case 4:
|
|
170
|
+
_b.sent();
|
|
171
|
+
expect(second).toHaveAttribute('aria-expanded', 'true');
|
|
172
|
+
return [2 /*return*/];
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}); });
|
|
176
|
+
it('drops a closed panel from the accessibility tree after the transition', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
177
|
+
var user, panel, closedAnswer;
|
|
178
|
+
return __generator(this, function (_a) {
|
|
179
|
+
switch (_a.label) {
|
|
180
|
+
case 0:
|
|
181
|
+
user = user_event_1.default.setup();
|
|
182
|
+
renderAccordion();
|
|
183
|
+
expect(react_2.screen.queryByRole('region')).not.toBeInTheDocument();
|
|
184
|
+
expect(react_2.screen.queryByRole('link', { name: 'siparişlerim' })).not.toBeInTheDocument();
|
|
185
|
+
return [4 /*yield*/, user.click(questions()[0])];
|
|
186
|
+
case 1:
|
|
187
|
+
_a.sent();
|
|
188
|
+
expect(react_2.screen.getByRole('link', { name: 'siparişlerim' })).toHaveAttribute('href', '/orders');
|
|
189
|
+
return [4 /*yield*/, user.click(questions()[0])];
|
|
190
|
+
case 2:
|
|
191
|
+
_a.sent();
|
|
192
|
+
panel = react_2.screen.getByRole('region', { name: 'İade nasıl yapılır?' });
|
|
193
|
+
(0, react_1.act)(function () {
|
|
194
|
+
panel.dispatchEvent(new Event('transitionend', { bubbles: true }));
|
|
195
|
+
});
|
|
196
|
+
expect(react_2.screen.queryByRole('region', { name: 'İade nasıl yapılır?' })).not.toBeInTheDocument();
|
|
197
|
+
closedAnswer = document.querySelector('a[href="/orders"]');
|
|
198
|
+
expect(closedAnswer).not.toBeNull();
|
|
199
|
+
expect(closedAnswer === null || closedAnswer === void 0 ? void 0 : closedAnswer.closest('[hidden]')).not.toBeNull();
|
|
200
|
+
return [2 /*return*/];
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}); });
|
|
204
|
+
it('lets every item stay open when collapseAll is set', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
205
|
+
var user, _a, first, second;
|
|
206
|
+
return __generator(this, function (_b) {
|
|
207
|
+
switch (_b.label) {
|
|
208
|
+
case 0:
|
|
209
|
+
user = user_event_1.default.setup();
|
|
210
|
+
renderAccordion({ collapseAll: true });
|
|
211
|
+
_a = questions(), first = _a[0], second = _a[1];
|
|
212
|
+
expect(first).toHaveAttribute('aria-expanded', 'true');
|
|
213
|
+
expect(second).toHaveAttribute('aria-expanded', 'true');
|
|
214
|
+
return [4 /*yield*/, user.click(first)];
|
|
215
|
+
case 1:
|
|
216
|
+
_b.sent();
|
|
217
|
+
expect(first).toHaveAttribute('aria-expanded', 'false');
|
|
218
|
+
expect(second).toHaveAttribute('aria-expanded', 'true');
|
|
219
|
+
return [2 /*return*/];
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}); });
|
|
223
|
+
it('tracks the open panel height when its content box changes', function () {
|
|
224
|
+
renderAccordion({ activeIndex: 0 });
|
|
225
|
+
var panel = react_2.screen.getByRole('region', { name: 'İade nasıl yapılır?' });
|
|
226
|
+
var observer = ResizeObserverMock.instances[0];
|
|
227
|
+
observer.emit(373);
|
|
228
|
+
expect(panel).toHaveStyle({ height: '373px' });
|
|
229
|
+
observer.emit(254);
|
|
230
|
+
expect(panel).toHaveStyle({ height: '254px' });
|
|
231
|
+
expect(ResizeObserverMock.instances).toHaveLength(1);
|
|
232
|
+
});
|
|
233
|
+
it('clears the height and stops observing when the panel closes', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
234
|
+
var user, panel, observer;
|
|
235
|
+
return __generator(this, function (_a) {
|
|
236
|
+
switch (_a.label) {
|
|
237
|
+
case 0:
|
|
238
|
+
user = user_event_1.default.setup();
|
|
239
|
+
renderAccordion({ activeIndex: 0 });
|
|
240
|
+
panel = react_2.screen.getByRole('region', { name: 'İade nasıl yapılır?' });
|
|
241
|
+
observer = ResizeObserverMock.instances[0];
|
|
242
|
+
observer.emit(373);
|
|
243
|
+
return [4 /*yield*/, user.click(questions()[0])];
|
|
244
|
+
case 1:
|
|
245
|
+
_a.sent();
|
|
246
|
+
expect(panel).toHaveStyle({ height: '0px' });
|
|
247
|
+
expect(observer.disconnect).toHaveBeenCalled();
|
|
248
|
+
return [2 /*return*/];
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
}); });
|
|
252
|
+
it('strips executable markup from the answer', function () {
|
|
253
|
+
(0, react_2.render)((0, jsx_runtime_1.jsx)(Accordion_1.default, { data: [
|
|
254
|
+
{
|
|
255
|
+
question: 'Güvenlik',
|
|
256
|
+
answer: '<p>güvenli</p><script>alert(1)</script><img src="x" onerror="alert(1)">',
|
|
257
|
+
},
|
|
258
|
+
], activeIndex: 0 }));
|
|
259
|
+
expect(react_2.screen.getByText('güvenli')).toBeInTheDocument();
|
|
260
|
+
expect(document.querySelector('script')).not.toBeInTheDocument();
|
|
261
|
+
expect(document.querySelector('[onerror]')).not.toBeInTheDocument();
|
|
262
|
+
});
|
|
263
|
+
});
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
import { AccordionStyledProps } from "./props";
|
|
3
|
+
type AccordionItemProps = {
|
|
4
|
+
title?: string;
|
|
5
|
+
content?: string;
|
|
6
|
+
index: number;
|
|
7
|
+
collapseAll?: boolean;
|
|
8
|
+
size?: AccordionStyledProps["$size"];
|
|
9
|
+
active: number | null;
|
|
10
|
+
setActive: (index: number | null) => void;
|
|
11
|
+
};
|
|
12
|
+
declare const AccordionItem: ({ title, content, index, collapseAll, size, active, setActive, }: AccordionItemProps) => React.JSX.Element;
|
|
11
13
|
export default AccordionItem;
|
|
@@ -16,32 +16,102 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
18
18
|
var react_1 = require("react");
|
|
19
|
+
var dompurify_1 = __importDefault(require("dompurify"));
|
|
19
20
|
var Accordion_styled_1 = require("./Accordion.styled");
|
|
20
21
|
var Icon_1 = __importDefault(require("../Icon/Icon"));
|
|
22
|
+
var readBorderBoxBlockSize = function (entry) {
|
|
23
|
+
var box = entry.borderBoxSize;
|
|
24
|
+
var first = Array.isArray(box) ? box[0] : box;
|
|
25
|
+
if (first && typeof first.blockSize === "number") {
|
|
26
|
+
return first.blockSize;
|
|
27
|
+
}
|
|
28
|
+
return entry.target.offsetHeight;
|
|
29
|
+
};
|
|
21
30
|
var AccordionItem = function (_a) {
|
|
22
31
|
var title = _a.title, content = _a.content, index = _a.index, collapseAll = _a.collapseAll, size = _a.size, active = _a.active, setActive = _a.setActive;
|
|
32
|
+
var baseId = (0, react_1.useId)();
|
|
33
|
+
var buttonId = "".concat(baseId, "-button");
|
|
34
|
+
var panelId = "".concat(baseId, "-panel");
|
|
35
|
+
var contentRef = (0, react_1.useRef)(null);
|
|
36
|
+
var panelRef = (0, react_1.useRef)(null);
|
|
37
|
+
var heightRef = (0, react_1.useRef)(0);
|
|
23
38
|
var _b = (0, react_1.useState)(0), height = _b[0], setHeight = _b[1];
|
|
24
39
|
var _c = (0, react_1.useState)(collapseAll ? true : false), activeItem = _c[0], setActiveItem = _c[1];
|
|
25
|
-
var
|
|
40
|
+
var isOpen = active === index || activeItem;
|
|
41
|
+
var _d = (0, react_1.useState)(!isOpen), hidePanel = _d[0], setHidePanel = _d[1];
|
|
42
|
+
var answerHtml = dompurify_1.default.sanitize(typeof content === "string" ? content : "");
|
|
43
|
+
var applyHeight = function (next) {
|
|
44
|
+
if (Object.is(heightRef.current, next))
|
|
45
|
+
return;
|
|
46
|
+
heightRef.current = next;
|
|
47
|
+
setHeight(next);
|
|
48
|
+
};
|
|
49
|
+
(0, react_1.useLayoutEffect)(function () {
|
|
50
|
+
if (!isOpen)
|
|
51
|
+
return;
|
|
52
|
+
applyHeight(0);
|
|
53
|
+
}, [isOpen]);
|
|
54
|
+
(0, react_1.useLayoutEffect)(function () {
|
|
55
|
+
if (isOpen && hidePanel)
|
|
56
|
+
setHidePanel(false);
|
|
57
|
+
}, [isOpen, hidePanel]);
|
|
26
58
|
(0, react_1.useEffect)(function () {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
59
|
+
if (isOpen || hidePanel)
|
|
60
|
+
return undefined;
|
|
61
|
+
var panel = panelRef.current;
|
|
62
|
+
if (!panel)
|
|
63
|
+
return undefined;
|
|
64
|
+
var hide = function () { return setHidePanel(true); };
|
|
65
|
+
var onTransitionEnd = function (event) {
|
|
66
|
+
if (event.target !== panel || (event.propertyName && event.propertyName !== "height"))
|
|
67
|
+
return;
|
|
68
|
+
hide();
|
|
69
|
+
};
|
|
70
|
+
panel.addEventListener("transitionend", onTransitionEnd);
|
|
71
|
+
var timeoutId = window.setTimeout(hide, Accordion_styled_1.ACCORDION_PANEL_TRANSITION_MS);
|
|
72
|
+
return function () {
|
|
73
|
+
panel.removeEventListener("transitionend", onTransitionEnd);
|
|
74
|
+
window.clearTimeout(timeoutId);
|
|
75
|
+
};
|
|
76
|
+
}, [isOpen, hidePanel]);
|
|
30
77
|
(0, react_1.useEffect)(function () {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
78
|
+
var node = contentRef.current;
|
|
79
|
+
if (!isOpen || hidePanel || !node) {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
var observer;
|
|
83
|
+
// Kapalı yükseklik (0) bir kare boyansın; aksi halde geçiş başlamaz.
|
|
84
|
+
var frame = window.requestAnimationFrame(function () {
|
|
85
|
+
applyHeight(node.offsetHeight);
|
|
86
|
+
if (typeof ResizeObserver === "undefined")
|
|
87
|
+
return;
|
|
88
|
+
observer = new ResizeObserver(function (entries) {
|
|
89
|
+
var entry = entries[0];
|
|
90
|
+
if (!entry)
|
|
91
|
+
return;
|
|
92
|
+
applyHeight(readBorderBoxBlockSize(entry));
|
|
93
|
+
});
|
|
94
|
+
observer.observe(node);
|
|
95
|
+
});
|
|
96
|
+
return function () {
|
|
97
|
+
window.cancelAnimationFrame(frame);
|
|
98
|
+
observer === null || observer === void 0 ? void 0 : observer.disconnect();
|
|
99
|
+
};
|
|
100
|
+
}, [isOpen, hidePanel, answerHtml]);
|
|
36
101
|
var handleCollapse = function () {
|
|
37
102
|
if (collapseAll) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
103
|
+
var nextOpen = !activeItem;
|
|
104
|
+
if (nextOpen)
|
|
105
|
+
setHidePanel(false);
|
|
106
|
+
setActiveItem(nextOpen);
|
|
107
|
+
return;
|
|
43
108
|
}
|
|
109
|
+
var nextActive = active === index ? null : index;
|
|
110
|
+
if (nextActive === index)
|
|
111
|
+
setHidePanel(false);
|
|
112
|
+
setActive(nextActive);
|
|
113
|
+
setActiveItem(false);
|
|
44
114
|
};
|
|
45
|
-
return ((0, jsx_runtime_1.jsxs)(Accordion_styled_1.Item, { children: [(0, jsx_runtime_1.jsxs)(Accordion_styled_1.ItemTitle, __assign({ "$size": size,
|
|
115
|
+
return ((0, jsx_runtime_1.jsxs)(Accordion_styled_1.Item, { children: [(0, jsx_runtime_1.jsxs)(Accordion_styled_1.ItemTitle, __assign({ type: "button", id: buttonId, "$size": size, "aria-expanded": isOpen, "aria-controls": panelId, onClick: handleCollapse, className: isOpen ? "active" : undefined }, { children: [(0, jsx_runtime_1.jsx)("div", { children: title }), (0, jsx_runtime_1.jsxs)("div", __assign({ "aria-hidden": "true" }, { children: [(0, jsx_runtime_1.jsx)(Icon_1.default, { name: "NegativeSmall" }), (0, jsx_runtime_1.jsx)(Icon_1.default, { name: "PlusSmall" })] }))] })), (0, jsx_runtime_1.jsx)(Accordion_styled_1.ItemContent, __assign({ id: panelId, role: "region", "aria-labelledby": buttonId, hidden: hidePanel, "$size": size, ref: panelRef, style: { height: isOpen ? height : 0 } }, { children: (0, jsx_runtime_1.jsx)("div", { ref: contentRef, dangerouslySetInnerHTML: { __html: answerHtml } }) }))] }));
|
|
46
116
|
};
|
|
47
117
|
exports.default = AccordionItem;
|
|
@@ -42,6 +42,6 @@ var CouponCode = function (_a) {
|
|
|
42
42
|
setIsExpanded(expanded);
|
|
43
43
|
}, [expanded]);
|
|
44
44
|
var toggleExpand = function () { return setIsExpanded(function (prevState) { return !prevState; }); };
|
|
45
|
-
return ((0, jsx_runtime_1.jsxs)(CouponCode_styled_1.CouponCodeStyled, __assign({ "$expanded": isExpanded, "$hasError": hasError }, other, { children: [(0, jsx_runtime_1.jsxs)("div", __assign({ onClick: toggleExpand, className: "header" }, { children: [(0, jsx_runtime_1.jsx)("strong", __assign({ className: "title" }, { children: title })), (0, jsx_runtime_1.jsx)(Icon_1.default, { name: "ArrowSmallDown" })] })), (0, jsx_runtime_1.jsxs)("div", __assign({ className: "body" }, { children: [(0, jsx_runtime_1.jsxs)(CouponCode_styled_1.CouponCodeFields, __assign({ "$hasError": hasError }, { children: [(0, jsx_runtime_1.jsx)(Input_1.default, { disabled: isInputDisabled, name: name, onChange: onChange, hasError: hasError, value: value, autoFocus: autoFocus, label: "", width: "auto", placeholder: placeholder, hasCopyButton: false }), (0, jsx_runtime_1.jsx)(Button_1.default, __assign({ width: buttonWidth, isLoading: isButtonLoading, disabled: buttonDisabled, size: "big", variant: buttonVariant }, { children: buttonText }))] })), hasError && errorMessage && ((0, jsx_runtime_1.jsxs)(CouponCode_styled_1.CouponCodeError, { children: [(0, jsx_runtime_1.jsx)(Icon_1.default, { name: "SwitchPassive" }), (0, jsx_runtime_1.jsx)("p", { children: errorMessage })] }))] }))] })));
|
|
45
|
+
return ((0, jsx_runtime_1.jsxs)(CouponCode_styled_1.CouponCodeStyled, __assign({ "$expanded": isExpanded, "$hasError": hasError }, other, { children: [(0, jsx_runtime_1.jsxs)("div", __assign({ onClick: toggleExpand, className: "header" }, { children: [(0, jsx_runtime_1.jsx)("strong", __assign({ className: "title" }, { children: title })), (0, jsx_runtime_1.jsx)(Icon_1.default, { name: "ArrowSmallDown" })] })), (0, jsx_runtime_1.jsxs)("div", __assign({ className: "body" }, { children: [(0, jsx_runtime_1.jsxs)(CouponCode_styled_1.CouponCodeFields, __assign({ "$hasError": hasError }, { children: [(0, jsx_runtime_1.jsx)(Input_1.default, { disabled: isInputDisabled, name: name, onChange: onChange, hasError: hasError, value: value, autoFocus: autoFocus, label: "", width: "auto", placeholder: placeholder, hasCopyButton: false }), (0, jsx_runtime_1.jsx)(Button_1.default, __assign({ width: buttonWidth, isLoading: isButtonLoading, disabled: buttonDisabled, size: "big", variant: buttonVariant, type: "submit" }, { children: buttonText }))] })), hasError && errorMessage && ((0, jsx_runtime_1.jsxs)(CouponCode_styled_1.CouponCodeError, { children: [(0, jsx_runtime_1.jsx)(Icon_1.default, { name: "SwitchPassive" }), (0, jsx_runtime_1.jsx)("p", { children: errorMessage })] }))] }))] })));
|
|
46
46
|
};
|
|
47
47
|
exports.default = CouponCode;
|
|
@@ -37,9 +37,11 @@ var TextLink_1 = __importDefault(require("../TextLink"));
|
|
|
37
37
|
var useOnClickOutside_1 = __importDefault(require("../../hooks/useOnClickOutside"));
|
|
38
38
|
var react_i18next_1 = require("react-i18next");
|
|
39
39
|
var bodyScrollLock_1 = require("./core/bodyScrollLock");
|
|
40
|
+
var modalFocus_1 = require("./core/modalFocus");
|
|
40
41
|
var Modal = function (_a) {
|
|
41
42
|
var _b = _a.size, size = _b === void 0 ? props_1.ModalDefault.size : _b, _c = _a.showCloseIcon, showCloseIcon = _c === void 0 ? props_1.ModalDefault.showCloseIcon : _c, _d = _a.showSkipButton, showSkipButton = _d === void 0 ? props_1.ModalDefault.showSkipButton : _d, _e = _a.skipButtonText, skipButtonText = _e === void 0 ? props_1.ModalDefault.skipButtonText : _e, _f = _a.onSkip, onSkip = _f === void 0 ? props_1.ModalDefault.onSkip : _f, _g = _a.showBackIcon, showBackIcon = _g === void 0 ? props_1.ModalDefault.showBackIcon : _g, _h = _a.backIconType, backIconType = _h === void 0 ? props_1.ModalDefault.backIconType : _h, _j = _a.hasCloseOnOutsideClick, hasCloseOnOutsideClick = _j === void 0 ? props_1.ModalDefault.hasCloseOnOutsideClick : _j, _k = _a.onClose, onClose = _k === void 0 ? props_1.ModalDefault.onClose : _k, _l = _a.onBack, onBack = _l === void 0 ? props_1.ModalDefault.onBack : _l, _m = _a.show, show = _m === void 0 ? props_1.ModalDefault.show : _m, _o = _a.showDivider, showDivider = _o === void 0 ? props_1.ModalDefault.showDivider : _o, _p = _a.title, title = _p === void 0 ? props_1.ModalDefault.title : _p, _q = _a.children, children = _q === void 0 ? props_1.ModalDefault.children : _q, _r = _a.modalFooter, modalFooter = _r === void 0 ? props_1.ModalDefault.modalFooter : _r, _s = _a.showPrimaryButton, showPrimaryButton = _s === void 0 ? props_1.ModalDefault.showPrimaryButton : _s, _t = _a.showSecondaryButton, showSecondaryButton = _t === void 0 ? props_1.ModalDefault.showSecondaryButton : _t, _u = _a.onPrimaryAction, onPrimaryAction = _u === void 0 ? props_1.ModalDefault.onPrimaryAction : _u, _v = _a.onSecondaryAction, onSecondaryAction = _v === void 0 ? props_1.ModalDefault.onSecondaryAction : _v, _w = _a.buttonsAlignment, buttonsAlignment = _w === void 0 ? props_1.ModalDefault.buttonsAlignment : _w, _x = _a.buttonsAlignmentOnMobile, buttonsAlignmentOnMobile = _x === void 0 ? props_1.ModalDefault.buttonsAlignmentOnMobile : _x, _y = _a.primaryButtonText, primaryButtonText = _y === void 0 ? props_1.ModalDefault.primaryButtonText : _y, _z = _a.secondaryButtonText, secondaryButtonText = _z === void 0 ? props_1.ModalDefault.secondaryButtonText : _z, _0 = _a.showHeaderBorder, showHeaderBorder = _0 === void 0 ? props_1.ModalDefault.showHeaderBorder : _0, _1 = _a.showFooterBorder, showFooterBorder = _1 === void 0 ? props_1.ModalDefault.showFooterBorder : _1, _2 = _a.autoHeight, autoHeight = _2 === void 0 ? props_1.ModalDefault.autoHeight : _2, _3 = _a.titleAlignment, titleAlignment = _3 === void 0 ? props_1.ModalDefault.titleAlignment : _3, _4 = _a.titleDescription, titleDescription = _4 === void 0 ? props_1.ModalDefault.titleDescription : _4, _5 = _a.isPrimaryButtonLoading, isPrimaryButtonLoading = _5 === void 0 ? props_1.ModalDefault.isPrimaryButtonLoading : _5, _6 = _a.primaryButtonIcon, primaryButtonIcon = _6 === void 0 ? props_1.ModalDefault.primaryButtonIcon : _6, _7 = _a.secondaryButtonIcon, secondaryButtonIcon = _7 === void 0 ? props_1.ModalDefault.secondaryButtonIcon : _7, _8 = _a.isSecondaryButtonLoading, isSecondaryButtonLoading = _8 === void 0 ? props_1.ModalDefault.isSecondaryButtonLoading : _8, _9 = _a.isPrimaryButtonDisabled, isPrimaryButtonDisabled = _9 === void 0 ? props_1.ModalDefault.isPrimaryButtonDisabled : _9, _10 = _a.isSecondaryButtonDisabled, isSecondaryButtonDisabled = _10 === void 0 ? props_1.ModalDefault.isSecondaryButtonDisabled : _10, _11 = _a.primaryButtonWidth, primaryButtonWidth = _11 === void 0 ? props_1.ModalDefault.primaryButtonWidth : _11, _12 = _a.secondaryButtonWidth, secondaryButtonWidth = _12 === void 0 ? props_1.ModalDefault.secondaryButtonWidth : _12, _13 = _a.customContent, customContent = _13 === void 0 ? props_1.ModalDefault.customContent : _13, _14 = _a.showHeader, showHeader = _14 === void 0 ? props_1.ModalDefault.showHeader : _14, _15 = _a.id, id = _15 === void 0 ? props_1.ModalDefault.id : _15, _16 = _a.renderInDOM, renderInDOM = _16 === void 0 ? props_1.ModalDefault.renderInDOM : _16, _17 = _a.portalContainer, portalContainer = _17 === void 0 ? props_1.ModalDefault.portalContainer : _17, _18 = _a.hasHeaderMinHeight, hasHeaderMinHeight = _18 === void 0 ? props_1.ModalDefault.hasHeaderMinHeight : _18, other = __rest(_a, ["size", "showCloseIcon", "showSkipButton", "skipButtonText", "onSkip", "showBackIcon", "backIconType", "hasCloseOnOutsideClick", "onClose", "onBack", "show", "showDivider", "title", "children", "modalFooter", "showPrimaryButton", "showSecondaryButton", "onPrimaryAction", "onSecondaryAction", "buttonsAlignment", "buttonsAlignmentOnMobile", "primaryButtonText", "secondaryButtonText", "showHeaderBorder", "showFooterBorder", "autoHeight", "titleAlignment", "titleDescription", "isPrimaryButtonLoading", "primaryButtonIcon", "secondaryButtonIcon", "isSecondaryButtonLoading", "isPrimaryButtonDisabled", "isSecondaryButtonDisabled", "primaryButtonWidth", "secondaryButtonWidth", "customContent", "showHeader", "id", "renderInDOM", "portalContainer", "hasHeaderMinHeight"]);
|
|
42
43
|
var t = (0, react_i18next_1.useTranslation)().t;
|
|
44
|
+
var titleId = (0, react_1.useId)();
|
|
43
45
|
var _19 = (0, react_1.useState)(show), showModal = _19[0], setShowModal = _19[1];
|
|
44
46
|
var _20 = (0, react_1.useState)(null), defaultPortalContainer = _20[0], setDefaultPortalContainer = _20[1];
|
|
45
47
|
(0, react_1.useEffect)(function () {
|
|
@@ -73,9 +75,16 @@ var Modal = function (_a) {
|
|
|
73
75
|
handleClose();
|
|
74
76
|
}
|
|
75
77
|
};
|
|
76
|
-
var modalRef = (0, react_1.useRef)();
|
|
78
|
+
var modalRef = (0, react_1.useRef)(null);
|
|
79
|
+
var handleCloseRef = (0, react_1.useRef)(handleClose);
|
|
80
|
+
handleCloseRef.current = handleClose;
|
|
77
81
|
(0, useOnClickOutside_1.default)(modalRef, onClose, hasCloseOnOutsideClick);
|
|
78
|
-
|
|
82
|
+
(0, react_1.useEffect)(function () {
|
|
83
|
+
if (!showModal || !modalRef.current)
|
|
84
|
+
return undefined;
|
|
85
|
+
return (0, modalFocus_1.bindModalFocus)(modalRef.current, function () { return handleCloseRef.current(); });
|
|
86
|
+
}, [showModal, resolvedPortalContainer]);
|
|
87
|
+
var modalContent = ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(Modal_styled_1.OverlayStyled, __assign({ id: "modalBackdrop_".concat(id), "$show": renderInDOM ? showModal : true }, { children: (0, jsx_runtime_1.jsxs)(Modal_styled_1.ModalStyled, __assign({ ref: modalRef, "$size": size, "$autoHeight": autoHeight, "$showHeaderBorder": showHeaderBorder, "$titleAlignment": titleAlignment, "$customContent": customContent, "$showFooterBorder": showFooterBorder, "$buttonsAlignment": buttonsAlignment, "$showSecondaryButton": showSecondaryButton, "$showDivider": showDivider, "$showHeader": showHeader, "$buttonsAlignmentOnMobile": buttonsAlignmentOnMobile, "$hasHeaderMinHeight": hasHeaderMinHeight }, other, { id: id, role: "dialog", "aria-modal": "true", "aria-labelledby": title ? titleId : undefined, tabIndex: -1 }, { children: [(0, jsx_runtime_1.jsxs)("div", __assign({ className: "header", hidden: showHeader === false }, { children: [showBackIcon ? (backIconType === 2 ? ((0, jsx_runtime_1.jsx)("div", __assign({ className: "modalTextLinkWrapper" }, { children: (0, jsx_runtime_1.jsx)(TextLink_1.default, __assign({ onClick: onBack, icon: "ArrowSmallLeft" }, { children: t("back") })) }))) : ((0, jsx_runtime_1.jsx)("button", __assign({ type: "button", onClick: onBack, className: "icon", "aria-label": t("back") }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { name: "ArrowLeftBig" }) })))) : (titleAlignment === "center" && (0, jsx_runtime_1.jsx)("div", { className: "empty" })), (0, jsx_runtime_1.jsxs)("div", __assign({ className: "title" }, { children: [title && ((0, jsx_runtime_1.jsx)("h5", __assign({ id: titleId }, { children: title }))), titleDescription && (0, jsx_runtime_1.jsx)("p", { children: titleDescription })] })), showCloseIcon ? ((0, jsx_runtime_1.jsx)("button", __assign({ type: "button", onClick: handleClose, className: "icon", "aria-label": t("close") }, { children: (0, jsx_runtime_1.jsx)(Icon_1.default, { name: "Closebig" }) }))) : showSkipButton ? ((0, jsx_runtime_1.jsx)("div", __assign({ className: "modalTextLinkWrapper skipButton" }, { children: (0, jsx_runtime_1.jsx)(TextLink_1.default, __assign({ onClick: handleSkip }, { children: skipButtonText })) }))) : ((0, jsx_runtime_1.jsx)("div", { className: "empty" }))] })), (0, jsx_runtime_1.jsx)("div", __assign({ className: "content" }, { children: (0, jsx_runtime_1.jsx)("div", __assign({ className: "contentInner" }, { children: children })) })), modalFooter ? modalFooter : (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (showPrimaryButton || showSecondaryButton) && (0, jsx_runtime_1.jsxs)("div", __assign({ className: "buttons" }, { children: [showPrimaryButton && ((0, jsx_runtime_1.jsx)(Button_1.default, __assign({ onClick: onPrimaryAction, size: "big", variant: "primary", isLoading: isPrimaryButtonLoading, disabled: isPrimaryButtonDisabled, width: primaryButtonWidth, icon: primaryButtonIcon }, { children: primaryButtonText }))), showSecondaryButton && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [buttonsAlignment === "vertical" && showDivider && ((0, jsx_runtime_1.jsx)(Divider_1.default, { text: t("or") })), (0, jsx_runtime_1.jsx)(Button_1.default, __assign({ onClick: onSecondaryAction, size: "big", variant: "inverted", isLoading: isSecondaryButtonLoading, disabled: isSecondaryButtonDisabled, width: secondaryButtonWidth, icon: secondaryButtonIcon }, { children: secondaryButtonText }))] }))] })) })] })) })) }));
|
|
79
88
|
if (!resolvedPortalContainer) {
|
|
80
89
|
return null;
|
|
81
90
|
}
|
|
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
10
|
exports.OverlayStyled = exports.ModalStyled = void 0;
|
|
11
11
|
var styled_components_1 = __importDefault(require("styled-components"));
|
|
12
12
|
var devices_1 = require("../../constants/devices");
|
|
13
|
-
exports.ModalStyled = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n background: var(--bg);\n border-radius: 0.5rem;\n box-sizing: border-box;\n max-height: min(calc(100dvh - 50px), 720px);\n min-height: 300px;\n display: grid;\n grid-template-rows: ", ";\n max-width: calc(100vw - 2rem);\n width: ", ";\n ", ";\n \n div.header {\n display: ", ";\n justify-content: space-between;\n align-items: center;\n padding: 24px;\n border-bottom: ", ";\n box-sizing: border-box;\n min-height: ", ";\n div.empty {\n width: 32px;\n height: 32px;\n }\n\n div.modalTextLinkWrapper{\n font:var(--body-bold-14-17);\n &:is(.skipButton){\n * {\n color: var(--text-soft) !important;\n }\n }\n }\n\n
|
|
13
|
+
exports.ModalStyled = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n background: var(--bg);\n &:focus {\n outline: none;\n }\n border-radius: 0.5rem;\n box-sizing: border-box;\n max-height: min(calc(100dvh - 50px), 720px);\n min-height: 300px;\n display: grid;\n grid-template-rows: ", ";\n max-width: calc(100vw - 2rem);\n width: ", ";\n ", ";\n \n div.header {\n display: ", ";\n justify-content: space-between;\n align-items: center;\n padding: 24px;\n border-bottom: ", ";\n box-sizing: border-box;\n min-height: ", ";\n div.empty {\n width: 32px;\n height: 32px;\n }\n\n div.modalTextLinkWrapper{\n font:var(--body-bold-14-17);\n &:is(.skipButton){\n * {\n color: var(--text-soft) !important;\n }\n }\n }\n\n button.icon {\n width: 32px;\n height: 32px;\n border: 0;\n padding: 0;\n appearance: none;\n border-radius: 0.5rem;\n cursor: pointer;\n background: var(--bg);\n transition: all .2s;\n color: var(--text);\n display: flex;\n align-items: center;\n justify-content: center;\n &:hover {\n box-shadow: 0 6px 30px var(--box-shadow-color);\n }\n &:focus-visible {\n outline: 2px solid var(--primary);\n outline-offset: 2px;\n }\n }\n div.title {\n h5 {\n margin: 0;\n font : ", ";\n }\n p {\n margin: 8px 0 0;\n font:var(--body-regular-14-17);\n }\n }\n \n }\n\n div.content {\n padding : ", ";\n overflow: auto;\n position: relative;\n .contentInner{\n height: 100%;\n [data-simplebar] {\n .simplebar-track.simplebar-vertical {\n width: 9px !important;\n }\n }\n }\n }\n\n div.buttons {\n padding: 1.5rem 1.5rem ", " 1.5rem;\n display: flex;\n box-sizing: border-box;\n border-top: ", ";\n ", "\n\n @media only screen and ", " {\n ", "\n }\n \n }\n"], ["\n background: var(--bg);\n &:focus {\n outline: none;\n }\n border-radius: 0.5rem;\n box-sizing: border-box;\n max-height: min(calc(100dvh - 50px), 720px);\n min-height: 300px;\n display: grid;\n grid-template-rows: ", ";\n max-width: calc(100vw - 2rem);\n width: ", ";\n ", ";\n \n div.header {\n display: ", ";\n justify-content: space-between;\n align-items: center;\n padding: 24px;\n border-bottom: ", ";\n box-sizing: border-box;\n min-height: ", ";\n div.empty {\n width: 32px;\n height: 32px;\n }\n\n div.modalTextLinkWrapper{\n font:var(--body-bold-14-17);\n &:is(.skipButton){\n * {\n color: var(--text-soft) !important;\n }\n }\n }\n\n button.icon {\n width: 32px;\n height: 32px;\n border: 0;\n padding: 0;\n appearance: none;\n border-radius: 0.5rem;\n cursor: pointer;\n background: var(--bg);\n transition: all .2s;\n color: var(--text);\n display: flex;\n align-items: center;\n justify-content: center;\n &:hover {\n box-shadow: 0 6px 30px var(--box-shadow-color);\n }\n &:focus-visible {\n outline: 2px solid var(--primary);\n outline-offset: 2px;\n }\n }\n div.title {\n h5 {\n margin: 0;\n font : ", ";\n }\n p {\n margin: 8px 0 0;\n font:var(--body-regular-14-17);\n }\n }\n \n }\n\n div.content {\n padding : ", ";\n overflow: auto;\n position: relative;\n .contentInner{\n height: 100%;\n [data-simplebar] {\n .simplebar-track.simplebar-vertical {\n width: 9px !important;\n }\n }\n }\n }\n\n div.buttons {\n padding: 1.5rem 1.5rem ", " 1.5rem;\n display: flex;\n box-sizing: border-box;\n border-top: ", ";\n ", "\n\n @media only screen and ", " {\n ", "\n }\n \n }\n"])), function (props) { return props.$showHeader === false ? '1fr auto' : 'auto 1fr auto'; }, function (props) {
|
|
14
14
|
switch (props.$size) {
|
|
15
15
|
case 'xxsmall':
|
|
16
16
|
return "311px";
|
|
@@ -10,15 +10,54 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
13
49
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
51
|
};
|
|
16
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
53
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
18
54
|
var react_1 = require("@testing-library/react");
|
|
55
|
+
var user_event_1 = __importDefault(require("@testing-library/user-event"));
|
|
19
56
|
var Modal_1 = __importDefault(require("./Modal"));
|
|
20
57
|
var props_1 = require("./props");
|
|
21
58
|
var bodyScrollLock_1 = require("./core/bodyScrollLock");
|
|
59
|
+
var modalFocus_1 = require("./core/modalFocus");
|
|
60
|
+
var i18n_1 = require("../../i18n/i18n");
|
|
22
61
|
var modalProps = function (overrides) {
|
|
23
62
|
if (overrides === void 0) { overrides = {}; }
|
|
24
63
|
return (__assign(__assign(__assign({}, props_1.ModalDefault), { title: 'Başlık', showBackIcon: false, showCloseIcon: true, showPrimaryButton: false, showSecondaryButton: false }), overrides));
|
|
@@ -27,11 +66,22 @@ var renderModal = function (props) {
|
|
|
27
66
|
if (props === void 0) { props = {}; }
|
|
28
67
|
return (0, react_1.render)((0, jsx_runtime_1.jsx)(Modal_1.default, __assign({}, modalProps(props))));
|
|
29
68
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
(
|
|
33
|
-
|
|
69
|
+
beforeAll(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
70
|
+
return __generator(this, function (_a) {
|
|
71
|
+
switch (_a.label) {
|
|
72
|
+
case 0: return [4 /*yield*/, (0, i18n_1.init)()];
|
|
73
|
+
case 1:
|
|
74
|
+
_a.sent();
|
|
75
|
+
return [2 /*return*/];
|
|
76
|
+
}
|
|
34
77
|
});
|
|
78
|
+
}); });
|
|
79
|
+
afterEach(function () {
|
|
80
|
+
(0, react_1.cleanup)();
|
|
81
|
+
(0, bodyScrollLock_1.resetBodyScrollLock)();
|
|
82
|
+
(0, modalFocus_1.resetModalFocus)();
|
|
83
|
+
});
|
|
84
|
+
describe('Modal body scroll lock', function () {
|
|
35
85
|
it('locks body scroll while open', function () {
|
|
36
86
|
renderModal({ onClose: jest.fn() });
|
|
37
87
|
expect(document.body).toHaveClass(bodyScrollLock_1.MODAL_BODY_LOCK_CLASS);
|
|
@@ -60,3 +110,96 @@ describe('Modal body scroll lock', function () {
|
|
|
60
110
|
expect(document.body).not.toHaveClass(bodyScrollLock_1.MODAL_BODY_LOCK_CLASS);
|
|
61
111
|
});
|
|
62
112
|
});
|
|
113
|
+
describe('Modal dialog focus', function () {
|
|
114
|
+
it('names the dialog from the title', function () {
|
|
115
|
+
renderModal({ onClose: jest.fn() });
|
|
116
|
+
expect(react_1.screen.getByRole('dialog', { name: 'Başlık' })).toHaveAttribute('aria-modal', 'true');
|
|
117
|
+
});
|
|
118
|
+
it('renders close as a button', function () {
|
|
119
|
+
renderModal({ onClose: jest.fn() });
|
|
120
|
+
expect(react_1.screen.getByRole('button', { name: 'Kapat' })).toHaveAttribute('type', 'button');
|
|
121
|
+
});
|
|
122
|
+
it('keeps Tab and Shift+Tab inside the dialog', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
123
|
+
var user;
|
|
124
|
+
return __generator(this, function (_a) {
|
|
125
|
+
switch (_a.label) {
|
|
126
|
+
case 0:
|
|
127
|
+
user = user_event_1.default.setup();
|
|
128
|
+
(0, react_1.render)((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("a", __assign({ href: "#orders" }, { children: "Sipari\u015Fler" })), (0, jsx_runtime_1.jsx)(Modal_1.default, __assign({}, modalProps({
|
|
129
|
+
onClose: jest.fn(),
|
|
130
|
+
children: (0, jsx_runtime_1.jsx)("input", { "aria-label": "S\u00F6zle\u015Fme" }),
|
|
131
|
+
})))] }));
|
|
132
|
+
expect(react_1.screen.getByRole('dialog', { name: 'Başlık' })).toHaveFocus();
|
|
133
|
+
return [4 /*yield*/, user.tab()];
|
|
134
|
+
case 1:
|
|
135
|
+
_a.sent();
|
|
136
|
+
expect(react_1.screen.getByRole('button', { name: 'Kapat' })).toHaveFocus();
|
|
137
|
+
return [4 /*yield*/, user.tab()];
|
|
138
|
+
case 2:
|
|
139
|
+
_a.sent();
|
|
140
|
+
expect(react_1.screen.getByRole('textbox', { name: 'Sözleşme' })).toHaveFocus();
|
|
141
|
+
return [4 /*yield*/, user.tab()];
|
|
142
|
+
case 3:
|
|
143
|
+
_a.sent();
|
|
144
|
+
expect(react_1.screen.getByRole('button', { name: 'Kapat' })).toHaveFocus();
|
|
145
|
+
expect(react_1.screen.getByRole('link', { name: 'Siparişler' })).not.toHaveFocus();
|
|
146
|
+
return [4 /*yield*/, user.tab({ shift: true })];
|
|
147
|
+
case 4:
|
|
148
|
+
_a.sent();
|
|
149
|
+
expect(react_1.screen.getByRole('textbox', { name: 'Sözleşme' })).toHaveFocus();
|
|
150
|
+
return [2 /*return*/];
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}); });
|
|
154
|
+
it('runs onClose on Escape', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
155
|
+
var user, onClose;
|
|
156
|
+
return __generator(this, function (_a) {
|
|
157
|
+
switch (_a.label) {
|
|
158
|
+
case 0:
|
|
159
|
+
user = user_event_1.default.setup();
|
|
160
|
+
onClose = jest.fn();
|
|
161
|
+
renderModal({ onClose: onClose });
|
|
162
|
+
return [4 /*yield*/, user.keyboard('{Escape}')];
|
|
163
|
+
case 1:
|
|
164
|
+
_a.sent();
|
|
165
|
+
expect(onClose).toHaveBeenCalledTimes(1);
|
|
166
|
+
return [2 /*return*/];
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}); });
|
|
170
|
+
it('closes on Escape when onClose is absent', function () {
|
|
171
|
+
renderModal();
|
|
172
|
+
react_1.fireEvent.keyDown(document.body, { key: 'Escape' });
|
|
173
|
+
expect(react_1.screen.queryByRole('dialog')).not.toBeInTheDocument();
|
|
174
|
+
});
|
|
175
|
+
it('returns focus to the control that opened it', function () {
|
|
176
|
+
var opener = document.createElement('button');
|
|
177
|
+
opener.type = 'button';
|
|
178
|
+
opener.textContent = 'Başlat';
|
|
179
|
+
document.body.appendChild(opener);
|
|
180
|
+
opener.focus();
|
|
181
|
+
var rerender = renderModal({ onClose: jest.fn() }).rerender;
|
|
182
|
+
expect(react_1.screen.getByRole('dialog', { name: 'Başlık' })).toHaveFocus();
|
|
183
|
+
rerender((0, jsx_runtime_1.jsx)(Modal_1.default, __assign({}, modalProps({ show: false, onClose: jest.fn() }))));
|
|
184
|
+
expect(opener).toHaveFocus();
|
|
185
|
+
opener.remove();
|
|
186
|
+
});
|
|
187
|
+
it('lets Escape close only the top dialog', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
188
|
+
var user, onCloseOuter, onCloseInner;
|
|
189
|
+
return __generator(this, function (_a) {
|
|
190
|
+
switch (_a.label) {
|
|
191
|
+
case 0:
|
|
192
|
+
user = user_event_1.default.setup();
|
|
193
|
+
onCloseOuter = jest.fn();
|
|
194
|
+
onCloseInner = jest.fn();
|
|
195
|
+
(0, react_1.render)((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Modal_1.default, __assign({}, modalProps({ title: 'Dış', onClose: onCloseOuter }))), (0, jsx_runtime_1.jsx)(Modal_1.default, __assign({}, modalProps({ title: 'İç', onClose: onCloseInner })))] }));
|
|
196
|
+
return [4 /*yield*/, user.keyboard('{Escape}')];
|
|
197
|
+
case 1:
|
|
198
|
+
_a.sent();
|
|
199
|
+
expect(onCloseInner).toHaveBeenCalledTimes(1);
|
|
200
|
+
expect(onCloseOuter).not.toHaveBeenCalled();
|
|
201
|
+
return [2 /*return*/];
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}); });
|
|
205
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resetModalFocus = exports.bindModalFocus = exports.getFocusableElements = void 0;
|
|
4
|
+
var FOCUSABLE_SELECTOR = [
|
|
5
|
+
'a[href]',
|
|
6
|
+
'button:not([disabled])',
|
|
7
|
+
'textarea:not([disabled])',
|
|
8
|
+
'input:not([disabled]):not([type="hidden"])',
|
|
9
|
+
'select:not([disabled])',
|
|
10
|
+
'[tabindex]:not([tabindex="-1"])',
|
|
11
|
+
].join(', ');
|
|
12
|
+
var isFocusable = function (element) {
|
|
13
|
+
if (element.closest('[hidden]'))
|
|
14
|
+
return false;
|
|
15
|
+
if (element.getAttribute('aria-hidden') === 'true')
|
|
16
|
+
return false;
|
|
17
|
+
if (element.hasAttribute('disabled'))
|
|
18
|
+
return false;
|
|
19
|
+
return element.tabIndex >= 0;
|
|
20
|
+
};
|
|
21
|
+
var getFocusableElements = function (root) {
|
|
22
|
+
return Array.from(root.querySelectorAll(FOCUSABLE_SELECTOR)).filter(isFocusable);
|
|
23
|
+
};
|
|
24
|
+
exports.getFocusableElements = getFocusableElements;
|
|
25
|
+
var cycleTab = function (event, root) {
|
|
26
|
+
var focusable = (0, exports.getFocusableElements)(root);
|
|
27
|
+
if (focusable.length === 0) {
|
|
28
|
+
event.preventDefault();
|
|
29
|
+
root.focus();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
var active = document.activeElement;
|
|
33
|
+
var current = focusable.indexOf(active);
|
|
34
|
+
var nextIndex = event.shiftKey
|
|
35
|
+
? current <= 0 ? focusable.length - 1 : current - 1
|
|
36
|
+
: current === -1 || current === focusable.length - 1 ? 0 : current + 1;
|
|
37
|
+
event.preventDefault();
|
|
38
|
+
focusable[nextIndex].focus();
|
|
39
|
+
};
|
|
40
|
+
var layers = [];
|
|
41
|
+
var topLayer = function () { return layers[layers.length - 1]; };
|
|
42
|
+
var onKeyDown = function (event) {
|
|
43
|
+
var top = topLayer();
|
|
44
|
+
if (!(top === null || top === void 0 ? void 0 : top.element.isConnected))
|
|
45
|
+
return;
|
|
46
|
+
if (event.key === 'Escape') {
|
|
47
|
+
if (event.defaultPrevented)
|
|
48
|
+
return;
|
|
49
|
+
event.preventDefault();
|
|
50
|
+
top.onEscape();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (event.key === 'Tab') {
|
|
54
|
+
cycleTab(event, top.element);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var listening = false;
|
|
58
|
+
var startListening = function () {
|
|
59
|
+
if (listening || typeof document === 'undefined')
|
|
60
|
+
return;
|
|
61
|
+
document.addEventListener('keydown', onKeyDown);
|
|
62
|
+
listening = true;
|
|
63
|
+
};
|
|
64
|
+
var stopListening = function () {
|
|
65
|
+
if (!listening || typeof document === 'undefined')
|
|
66
|
+
return;
|
|
67
|
+
document.removeEventListener('keydown', onKeyDown);
|
|
68
|
+
listening = false;
|
|
69
|
+
};
|
|
70
|
+
var rememberOpener = function () {
|
|
71
|
+
var active = document.activeElement;
|
|
72
|
+
if (!(active instanceof HTMLElement))
|
|
73
|
+
return null;
|
|
74
|
+
if (active === document.body || active === document.documentElement)
|
|
75
|
+
return null;
|
|
76
|
+
return active;
|
|
77
|
+
};
|
|
78
|
+
var bindModalFocus = function (element, onEscape) {
|
|
79
|
+
var id = Symbol('modal-focus');
|
|
80
|
+
var opener = rememberOpener();
|
|
81
|
+
layers.push({ id: id, element: element, onEscape: onEscape });
|
|
82
|
+
startListening();
|
|
83
|
+
element.focus();
|
|
84
|
+
return function () {
|
|
85
|
+
var index = layers.findIndex(function (layer) { return layer.id === id; });
|
|
86
|
+
var wasTop = index === layers.length - 1;
|
|
87
|
+
if (index >= 0)
|
|
88
|
+
layers.splice(index, 1);
|
|
89
|
+
if (layers.length === 0)
|
|
90
|
+
stopListening();
|
|
91
|
+
if (!wasTop)
|
|
92
|
+
return;
|
|
93
|
+
if (opener === null || opener === void 0 ? void 0 : opener.isConnected) {
|
|
94
|
+
opener.focus();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
var next = topLayer();
|
|
98
|
+
next === null || next === void 0 ? void 0 : next.element.focus();
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
exports.bindModalFocus = bindModalFocus;
|
|
102
|
+
var resetModalFocus = function () {
|
|
103
|
+
layers.length = 0;
|
|
104
|
+
stopListening();
|
|
105
|
+
};
|
|
106
|
+
exports.resetModalFocus = resetModalFocus;
|