1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | const index = require('./index-a0a08b2a.js');
|
6 | const ionicGlobal = require('./ionic-global-06f21c1a.js');
|
7 | const helpers = require('./helpers-d381ec4d.js');
|
8 | const theme = require('./theme-30b7a575.js');
|
9 |
|
10 | const textareaIosCss = ".sc-ion-textarea-ios-h{--background:initial;--color:initial;--placeholder-color:initial;--placeholder-font-style:initial;--placeholder-font-weight:initial;--placeholder-opacity:.5;--padding-top:0;--padding-end:0;--padding-bottom:0;--padding-start:0;--border-radius:0;display:block;position:relative;-ms-flex:1;flex:1;width:100%;background:var(--background);color:var(--color);font-family:var(--ion-font-family, inherit);white-space:pre-wrap;z-index:2;-webkit-box-sizing:border-box;box-sizing:border-box}.ion-color.sc-ion-textarea-ios-h{background:initial}.ion-color.sc-ion-textarea-ios-h{color:var(--ion-color-base)}ion-item.sc-ion-textarea-ios-h,ion-item .sc-ion-textarea-ios-h{-ms-flex-item-align:baseline;align-self:baseline}ion-item.sc-ion-textarea-ios-h:not(.item-label),ion-item:not(.item-label) .sc-ion-textarea-ios-h{--padding-start:0}.textarea-wrapper.sc-ion-textarea-ios{min-width:inherit;max-width:inherit;min-height:inherit;max-height:inherit}.native-textarea.sc-ion-textarea-ios{border-radius:var(--border-radius);margin-left:0;margin-right:0;margin-top:0;margin-bottom:0;padding-left:var(--padding-start);padding-right:var(--padding-end);padding-top:var(--padding-top);padding-bottom:var(--padding-bottom);font-family:inherit;font-size:inherit;font-style:inherit;font-weight:inherit;letter-spacing:inherit;text-decoration:inherit;text-indent:inherit;text-overflow:inherit;text-transform:inherit;text-align:inherit;white-space:inherit;color:inherit;display:block;width:100%;max-width:100%;max-height:100%;border:0;outline:none;background:transparent;-webkit-box-sizing:border-box;box-sizing:border-box;resize:none;-webkit-appearance:none;-moz-appearance:none;appearance:none}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){.native-textarea.sc-ion-textarea-ios{padding-left:unset;padding-right:unset;-webkit-padding-start:var(--padding-start);padding-inline-start:var(--padding-start);-webkit-padding-end:var(--padding-end);padding-inline-end:var(--padding-end)}}.native-textarea.sc-ion-textarea-ios::-webkit-input-placeholder{padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-textarea.sc-ion-textarea-ios::-moz-placeholder{padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-textarea.sc-ion-textarea-ios:-ms-input-placeholder{padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-textarea.sc-ion-textarea-ios::-ms-input-placeholder{padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-textarea.sc-ion-textarea-ios::placeholder{padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-textarea[disabled].sc-ion-textarea-ios{opacity:0.4}.cloned-input.sc-ion-textarea-ios{left:0;top:0;position:absolute;pointer-events:none}[dir=rtl].sc-ion-textarea-ios .cloned-input.sc-ion-textarea-ios,[dir=rtl].sc-ion-textarea-ios-h .cloned-input.sc-ion-textarea-ios,[dir=rtl] .sc-ion-textarea-ios-h .cloned-input.sc-ion-textarea-ios{left:unset;right:unset;right:0}.item-label-floating.item-has-placeholder.sc-ion-textarea-ios-h:not(.item-has-value),.item-label-floating.item-has-placeholder:not(.item-has-value) .sc-ion-textarea-ios-h{opacity:0}.item-label-floating.item-has-placeholder.sc-ion-textarea-ios-h:not(.item-has-value).item-has-focus,.item-label-floating.item-has-placeholder:not(.item-has-value).item-has-focus .sc-ion-textarea-ios-h{-webkit-transition:opacity 0.15s cubic-bezier(0.4, 0, 0.2, 1);transition:opacity 0.15s cubic-bezier(0.4, 0, 0.2, 1);opacity:1}.sc-ion-textarea-ios-h{--padding-top:10px;--padding-end:10px;--padding-bottom:10px;--padding-start:0;font-size:inherit}.item-label-stacked.sc-ion-textarea-ios-h,.item-label-stacked .sc-ion-textarea-ios-h,.item-label-floating.sc-ion-textarea-ios-h,.item-label-floating .sc-ion-textarea-ios-h{--padding-top:8px;--padding-bottom:8px;--padding-start:0px}";
|
11 |
|
12 | const textareaMdCss = ".sc-ion-textarea-md-h{--background:initial;--color:initial;--placeholder-color:initial;--placeholder-font-style:initial;--placeholder-font-weight:initial;--placeholder-opacity:.5;--padding-top:0;--padding-end:0;--padding-bottom:0;--padding-start:0;--border-radius:0;display:block;position:relative;-ms-flex:1;flex:1;width:100%;background:var(--background);color:var(--color);font-family:var(--ion-font-family, inherit);white-space:pre-wrap;z-index:2;-webkit-box-sizing:border-box;box-sizing:border-box}.ion-color.sc-ion-textarea-md-h{background:initial}.ion-color.sc-ion-textarea-md-h{color:var(--ion-color-base)}ion-item.sc-ion-textarea-md-h,ion-item .sc-ion-textarea-md-h{-ms-flex-item-align:baseline;align-self:baseline}ion-item.sc-ion-textarea-md-h:not(.item-label),ion-item:not(.item-label) .sc-ion-textarea-md-h{--padding-start:0}.textarea-wrapper.sc-ion-textarea-md{min-width:inherit;max-width:inherit;min-height:inherit;max-height:inherit}.native-textarea.sc-ion-textarea-md{border-radius:var(--border-radius);margin-left:0;margin-right:0;margin-top:0;margin-bottom:0;padding-left:var(--padding-start);padding-right:var(--padding-end);padding-top:var(--padding-top);padding-bottom:var(--padding-bottom);font-family:inherit;font-size:inherit;font-style:inherit;font-weight:inherit;letter-spacing:inherit;text-decoration:inherit;text-indent:inherit;text-overflow:inherit;text-transform:inherit;text-align:inherit;white-space:inherit;color:inherit;display:block;width:100%;max-width:100%;max-height:100%;border:0;outline:none;background:transparent;-webkit-box-sizing:border-box;box-sizing:border-box;resize:none;-webkit-appearance:none;-moz-appearance:none;appearance:none}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){.native-textarea.sc-ion-textarea-md{padding-left:unset;padding-right:unset;-webkit-padding-start:var(--padding-start);padding-inline-start:var(--padding-start);-webkit-padding-end:var(--padding-end);padding-inline-end:var(--padding-end)}}.native-textarea.sc-ion-textarea-md::-webkit-input-placeholder{padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-textarea.sc-ion-textarea-md::-moz-placeholder{padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-textarea.sc-ion-textarea-md:-ms-input-placeholder{padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-textarea.sc-ion-textarea-md::-ms-input-placeholder{padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-textarea.sc-ion-textarea-md::placeholder{padding-left:0;padding-right:0;padding-top:0;padding-bottom:0;color:var(--placeholder-color);font-family:inherit;font-style:var(--placeholder-font-style);font-weight:var(--placeholder-font-weight);opacity:var(--placeholder-opacity)}.native-textarea[disabled].sc-ion-textarea-md{opacity:0.4}.cloned-input.sc-ion-textarea-md{left:0;top:0;position:absolute;pointer-events:none}[dir=rtl].sc-ion-textarea-md .cloned-input.sc-ion-textarea-md,[dir=rtl].sc-ion-textarea-md-h .cloned-input.sc-ion-textarea-md,[dir=rtl] .sc-ion-textarea-md-h .cloned-input.sc-ion-textarea-md{left:unset;right:unset;right:0}.item-label-floating.item-has-placeholder.sc-ion-textarea-md-h:not(.item-has-value),.item-label-floating.item-has-placeholder:not(.item-has-value) .sc-ion-textarea-md-h{opacity:0}.item-label-floating.item-has-placeholder.sc-ion-textarea-md-h:not(.item-has-value).item-has-focus,.item-label-floating.item-has-placeholder:not(.item-has-value).item-has-focus .sc-ion-textarea-md-h{-webkit-transition:opacity 0.15s cubic-bezier(0.4, 0, 0.2, 1);transition:opacity 0.15s cubic-bezier(0.4, 0, 0.2, 1);opacity:1}.sc-ion-textarea-md-h{--padding-top:10px;--padding-end:0;--padding-bottom:11px;--padding-start:8px;margin-left:0;margin-right:0;margin-top:8px;margin-bottom:0;font-size:inherit}.item-label-stacked.sc-ion-textarea-md-h,.item-label-stacked .sc-ion-textarea-md-h,.item-label-floating.sc-ion-textarea-md-h,.item-label-floating .sc-ion-textarea-md-h{--padding-top:8px;--padding-bottom:8px;--padding-start:0}";
|
13 |
|
14 | const Textarea = class {
|
15 | constructor(hostRef) {
|
16 | index.registerInstance(this, hostRef);
|
17 | this.ionChange = index.createEvent(this, "ionChange", 7);
|
18 | this.ionInput = index.createEvent(this, "ionInput", 7);
|
19 | this.ionStyle = index.createEvent(this, "ionStyle", 7);
|
20 | this.ionBlur = index.createEvent(this, "ionBlur", 7);
|
21 | this.ionFocus = index.createEvent(this, "ionFocus", 7);
|
22 | this.inputId = `ion-textarea-${textareaIds++}`;
|
23 | this.didBlurAfterEdit = false;
|
24 | this.inheritedAttributes = {};
|
25 | |
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | this.fireFocusEvents = true;
|
34 | this.hasFocus = false;
|
35 | |
36 |
|
37 |
|
38 | this.autocapitalize = 'none';
|
39 | |
40 |
|
41 |
|
42 | this.autofocus = false;
|
43 | |
44 |
|
45 |
|
46 | this.clearOnEdit = false;
|
47 | |
48 |
|
49 |
|
50 | this.debounce = 0;
|
51 | |
52 |
|
53 |
|
54 | this.disabled = false;
|
55 | |
56 |
|
57 |
|
58 | this.name = this.inputId;
|
59 | |
60 |
|
61 |
|
62 | this.readonly = false;
|
63 | |
64 |
|
65 |
|
66 | this.required = false;
|
67 | |
68 |
|
69 |
|
70 | this.spellcheck = false;
|
71 | |
72 |
|
73 |
|
74 | this.autoGrow = false;
|
75 | |
76 |
|
77 |
|
78 | this.value = '';
|
79 | this.onInput = (ev) => {
|
80 | if (this.nativeInput) {
|
81 | this.value = this.nativeInput.value;
|
82 | }
|
83 | this.emitStyle();
|
84 | this.ionInput.emit(ev);
|
85 | };
|
86 | this.onFocus = (ev) => {
|
87 | this.hasFocus = true;
|
88 | this.focusChange();
|
89 | if (this.fireFocusEvents) {
|
90 | this.ionFocus.emit(ev);
|
91 | }
|
92 | };
|
93 | this.onBlur = (ev) => {
|
94 | this.hasFocus = false;
|
95 | this.focusChange();
|
96 | if (this.fireFocusEvents) {
|
97 | this.ionBlur.emit(ev);
|
98 | }
|
99 | };
|
100 | this.onKeyDown = () => {
|
101 | this.checkClearOnEdit();
|
102 | };
|
103 | }
|
104 | debounceChanged() {
|
105 | this.ionChange = helpers.debounceEvent(this.ionChange, this.debounce);
|
106 | }
|
107 | disabledChanged() {
|
108 | this.emitStyle();
|
109 | }
|
110 | |
111 |
|
112 |
|
113 | valueChanged() {
|
114 | const nativeInput = this.nativeInput;
|
115 | const value = this.getValue();
|
116 | if (nativeInput && nativeInput.value !== value) {
|
117 | nativeInput.value = value;
|
118 | }
|
119 | this.runAutoGrow();
|
120 | this.emitStyle();
|
121 | this.ionChange.emit({ value });
|
122 | }
|
123 | connectedCallback() {
|
124 | this.emitStyle();
|
125 | this.debounceChanged();
|
126 | {
|
127 | document.dispatchEvent(new CustomEvent('ionInputDidLoad', {
|
128 | detail: this.el
|
129 | }));
|
130 | }
|
131 | }
|
132 | disconnectedCallback() {
|
133 | {
|
134 | document.dispatchEvent(new CustomEvent('ionInputDidUnload', {
|
135 | detail: this.el
|
136 | }));
|
137 | }
|
138 | }
|
139 | componentWillLoad() {
|
140 | this.inheritedAttributes = helpers.inheritAttributes(this.el, ['title']);
|
141 | }
|
142 | componentDidLoad() {
|
143 | helpers.raf(() => this.runAutoGrow());
|
144 | }
|
145 | runAutoGrow() {
|
146 | const nativeInput = this.nativeInput;
|
147 | if (nativeInput && this.autoGrow) {
|
148 | index.readTask(() => {
|
149 | nativeInput.style.height = 'auto';
|
150 | nativeInput.style.height = nativeInput.scrollHeight + 'px';
|
151 | if (this.textareaWrapper) {
|
152 | this.textareaWrapper.style.height = nativeInput.scrollHeight + 'px';
|
153 | }
|
154 | });
|
155 | }
|
156 | }
|
157 | |
158 |
|
159 |
|
160 |
|
161 | async setFocus() {
|
162 | if (this.nativeInput) {
|
163 | this.nativeInput.focus();
|
164 | }
|
165 | }
|
166 | |
167 |
|
168 |
|
169 |
|
170 |
|
171 | async setBlur() {
|
172 | if (this.nativeInput) {
|
173 | this.nativeInput.blur();
|
174 | }
|
175 | }
|
176 | |
177 |
|
178 |
|
179 | getInputElement() {
|
180 | return Promise.resolve(this.nativeInput);
|
181 | }
|
182 | emitStyle() {
|
183 | this.ionStyle.emit({
|
184 | 'interactive': true,
|
185 | 'textarea': true,
|
186 | 'input': true,
|
187 | 'interactive-disabled': this.disabled,
|
188 | 'has-placeholder': this.placeholder != null,
|
189 | 'has-value': this.hasValue(),
|
190 | 'has-focus': this.hasFocus
|
191 | });
|
192 | }
|
193 | |
194 |
|
195 |
|
196 | checkClearOnEdit() {
|
197 | if (!this.clearOnEdit) {
|
198 | return;
|
199 | }
|
200 |
|
201 | if (this.didBlurAfterEdit && this.hasValue()) {
|
202 |
|
203 | this.value = '';
|
204 | }
|
205 |
|
206 | this.didBlurAfterEdit = false;
|
207 | }
|
208 | focusChange() {
|
209 |
|
210 | if (this.clearOnEdit && !this.hasFocus && this.hasValue()) {
|
211 | this.didBlurAfterEdit = true;
|
212 | }
|
213 | this.emitStyle();
|
214 | }
|
215 | hasValue() {
|
216 | return this.getValue() !== '';
|
217 | }
|
218 | getValue() {
|
219 | return this.value || '';
|
220 | }
|
221 | render() {
|
222 | const mode = ionicGlobal.getIonMode(this);
|
223 | const value = this.getValue();
|
224 | const labelId = this.inputId + '-lbl';
|
225 | const label = helpers.findItemLabel(this.el);
|
226 | if (label) {
|
227 | label.id = labelId;
|
228 | }
|
229 | return (index.h(index.Host, { "aria-disabled": this.disabled ? 'true' : null, class: theme.createColorClasses(this.color, {
|
230 | [mode]: true,
|
231 | }) }, index.h("div", { class: "textarea-wrapper", ref: el => this.textareaWrapper = el }, index.h("textarea", Object.assign({ class: "native-textarea", "aria-labelledby": label ? labelId : null, ref: el => this.nativeInput = el, autoCapitalize: this.autocapitalize, autoFocus: this.autofocus, enterKeyHint: this.enterkeyhint, inputMode: this.inputmode, disabled: this.disabled, maxLength: this.maxlength, minLength: this.minlength, name: this.name, placeholder: this.placeholder || '', readOnly: this.readonly, required: this.required, spellcheck: this.spellcheck, cols: this.cols, rows: this.rows, wrap: this.wrap, onInput: this.onInput, onBlur: this.onBlur, onFocus: this.onFocus, onKeyDown: this.onKeyDown }, this.inheritedAttributes), value))));
|
232 | }
|
233 | get el() { return index.getElement(this); }
|
234 | static get watchers() { return {
|
235 | "debounce": ["debounceChanged"],
|
236 | "disabled": ["disabledChanged"],
|
237 | "value": ["valueChanged"]
|
238 | }; }
|
239 | };
|
240 | let textareaIds = 0;
|
241 | Textarea.style = {
|
242 | ios: textareaIosCss,
|
243 | md: textareaMdCss
|
244 | };
|
245 |
|
246 | exports.ion_textarea = Textarea;
|