UNPKG

17.1 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5const index = require('./index-a0a08b2a.js');
6const ionicGlobal = require('./ionic-global-06f21c1a.js');
7const helpers = require('./helpers-d381ec4d.js');
8const theme = require('./theme-30b7a575.js');
9
10const 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
12const 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
14const 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 * This is required for a WebKit bug which requires us to
27 * blur and focus an input to properly focus the input in
28 * an item with delegatesFocus. It will no longer be needed
29 * with iOS 14.
30 *
31 * @internal
32 */
33 this.fireFocusEvents = true;
34 this.hasFocus = false;
35 /**
36 * Indicates whether and how the text value should be automatically capitalized as it is entered/edited by the user.
37 */
38 this.autocapitalize = 'none';
39 /**
40 * This Boolean attribute lets you specify that a form control should have input focus when the page loads.
41 */
42 this.autofocus = false;
43 /**
44 * If `true`, the value will be cleared after focus upon edit. Defaults to `true` when `type` is `"password"`, `false` for all other types.
45 */
46 this.clearOnEdit = false;
47 /**
48 * Set the amount of time, in milliseconds, to wait to trigger the `ionChange` event after each keystroke. This also impacts form bindings such as `ngModel` or `v-model`.
49 */
50 this.debounce = 0;
51 /**
52 * If `true`, the user cannot interact with the textarea.
53 */
54 this.disabled = false;
55 /**
56 * The name of the control, which is submitted with the form data.
57 */
58 this.name = this.inputId;
59 /**
60 * If `true`, the user cannot modify the value.
61 */
62 this.readonly = false;
63 /**
64 * If `true`, the user must fill in a value before submitting a form.
65 */
66 this.required = false;
67 /**
68 * If `true`, the element will have its spelling and grammar checked.
69 */
70 this.spellcheck = false;
71 /**
72 * If `true`, the element height will increase based on the value.
73 */
74 this.autoGrow = false;
75 /**
76 * The value of the textarea.
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 * Update the native input element when the value changes
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 * Sets focus on the native `textarea` in `ion-textarea`. Use this method instead of the global
159 * `textarea.focus()`.
160 */
161 async setFocus() {
162 if (this.nativeInput) {
163 this.nativeInput.focus();
164 }
165 }
166 /**
167 * Sets blur on the native `textarea` in `ion-textarea`. Use this method instead of the global
168 * `textarea.blur()`.
169 * @internal
170 */
171 async setBlur() {
172 if (this.nativeInput) {
173 this.nativeInput.blur();
174 }
175 }
176 /**
177 * Returns the native `<textarea>` element used under the hood.
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 * Check if we need to clear the text input if clearOnEdit is enabled
195 */
196 checkClearOnEdit() {
197 if (!this.clearOnEdit) {
198 return;
199 }
200 // Did the input value change after it was blurred and edited?
201 if (this.didBlurAfterEdit && this.hasValue()) {
202 // Clear the input
203 this.value = '';
204 }
205 // Reset the flag
206 this.didBlurAfterEdit = false;
207 }
208 focusChange() {
209 // If clearOnEdit is enabled and the input blurred but has a value, set a flag
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};
240let textareaIds = 0;
241Textarea.style = {
242 ios: textareaIosCss,
243 md: textareaMdCss
244};
245
246exports.ion_textarea = Textarea;