1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | import { __assign, __extends } from "tslib";
|
24 | import { MDCFoundation } from '@material/base/foundation';
|
25 | import { cssClasses, strings } from './constants';
|
26 | var MDCTextFieldHelperTextFoundation = (function (_super) {
|
27 | __extends(MDCTextFieldHelperTextFoundation, _super);
|
28 | function MDCTextFieldHelperTextFoundation(adapter) {
|
29 | return _super.call(this, __assign(__assign({}, MDCTextFieldHelperTextFoundation.defaultAdapter), adapter)) || this;
|
30 | }
|
31 | Object.defineProperty(MDCTextFieldHelperTextFoundation, "cssClasses", {
|
32 | get: function () {
|
33 | return cssClasses;
|
34 | },
|
35 | enumerable: false,
|
36 | configurable: true
|
37 | });
|
38 | Object.defineProperty(MDCTextFieldHelperTextFoundation, "strings", {
|
39 | get: function () {
|
40 | return strings;
|
41 | },
|
42 | enumerable: false,
|
43 | configurable: true
|
44 | });
|
45 | Object.defineProperty(MDCTextFieldHelperTextFoundation, "defaultAdapter", {
|
46 | |
47 |
|
48 |
|
49 | get: function () {
|
50 |
|
51 | return {
|
52 | addClass: function () { return undefined; },
|
53 | removeClass: function () { return undefined; },
|
54 | hasClass: function () { return false; },
|
55 | getAttr: function () { return null; },
|
56 | setAttr: function () { return undefined; },
|
57 | removeAttr: function () { return undefined; },
|
58 | setContent: function () { return undefined; },
|
59 | };
|
60 |
|
61 | },
|
62 | enumerable: false,
|
63 | configurable: true
|
64 | });
|
65 | MDCTextFieldHelperTextFoundation.prototype.getId = function () {
|
66 | return this.adapter.getAttr('id');
|
67 | };
|
68 | MDCTextFieldHelperTextFoundation.prototype.isVisible = function () {
|
69 | return this.adapter.getAttr(strings.ARIA_HIDDEN) !== 'true';
|
70 | };
|
71 | |
72 |
|
73 |
|
74 | MDCTextFieldHelperTextFoundation.prototype.setContent = function (content) {
|
75 | this.adapter.setContent(content);
|
76 | };
|
77 | MDCTextFieldHelperTextFoundation.prototype.isPersistent = function () {
|
78 | return this.adapter.hasClass(cssClasses.HELPER_TEXT_PERSISTENT);
|
79 | };
|
80 | |
81 |
|
82 |
|
83 | MDCTextFieldHelperTextFoundation.prototype.setPersistent = function (isPersistent) {
|
84 | if (isPersistent) {
|
85 | this.adapter.addClass(cssClasses.HELPER_TEXT_PERSISTENT);
|
86 | }
|
87 | else {
|
88 | this.adapter.removeClass(cssClasses.HELPER_TEXT_PERSISTENT);
|
89 | }
|
90 | };
|
91 | |
92 |
|
93 |
|
94 | MDCTextFieldHelperTextFoundation.prototype.isValidation = function () {
|
95 | return this.adapter.hasClass(cssClasses.HELPER_TEXT_VALIDATION_MSG);
|
96 | };
|
97 | |
98 |
|
99 |
|
100 | MDCTextFieldHelperTextFoundation.prototype.setValidation = function (isValidation) {
|
101 | if (isValidation) {
|
102 | this.adapter.addClass(cssClasses.HELPER_TEXT_VALIDATION_MSG);
|
103 | }
|
104 | else {
|
105 | this.adapter.removeClass(cssClasses.HELPER_TEXT_VALIDATION_MSG);
|
106 | }
|
107 | };
|
108 | |
109 |
|
110 |
|
111 | MDCTextFieldHelperTextFoundation.prototype.showToScreenReader = function () {
|
112 | this.adapter.removeAttr(strings.ARIA_HIDDEN);
|
113 | };
|
114 | |
115 |
|
116 |
|
117 | MDCTextFieldHelperTextFoundation.prototype.setValidity = function (inputIsValid) {
|
118 | var helperTextIsPersistent = this.adapter.hasClass(cssClasses.HELPER_TEXT_PERSISTENT);
|
119 | var helperTextIsValidationMsg = this.adapter.hasClass(cssClasses.HELPER_TEXT_VALIDATION_MSG);
|
120 | var validationMsgNeedsDisplay = helperTextIsValidationMsg && !inputIsValid;
|
121 | if (validationMsgNeedsDisplay) {
|
122 | this.showToScreenReader();
|
123 |
|
124 |
|
125 | if (this.adapter.getAttr(strings.ROLE) === 'alert') {
|
126 | this.refreshAlertRole();
|
127 | }
|
128 | else {
|
129 | this.adapter.setAttr(strings.ROLE, 'alert');
|
130 | }
|
131 | }
|
132 | else {
|
133 | this.adapter.removeAttr(strings.ROLE);
|
134 | }
|
135 | if (!helperTextIsPersistent && !validationMsgNeedsDisplay) {
|
136 | this.hide();
|
137 | }
|
138 | };
|
139 | |
140 |
|
141 |
|
142 | MDCTextFieldHelperTextFoundation.prototype.hide = function () {
|
143 | this.adapter.setAttr(strings.ARIA_HIDDEN, 'true');
|
144 | };
|
145 | MDCTextFieldHelperTextFoundation.prototype.refreshAlertRole = function () {
|
146 | var _this = this;
|
147 | this.adapter.removeAttr(strings.ROLE);
|
148 | requestAnimationFrame(function () {
|
149 | _this.adapter.setAttr(strings.ROLE, 'alert');
|
150 | });
|
151 | };
|
152 | return MDCTextFieldHelperTextFoundation;
|
153 | }(MDCFoundation));
|
154 | export { MDCTextFieldHelperTextFoundation };
|
155 |
|
156 | export default MDCTextFieldHelperTextFoundation;
|
157 |
|
\ | No newline at end of file |