krl-alfred 2.25.6 → 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/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
|
@@ -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;
|