riku
2025-04-27 f46786f11c5c08ead7501a82e5a71430ad69b782
miniprogram_npm/tdesign-miniprogram/input/input.js
@@ -7,7 +7,7 @@
import { SuperComponent, wxComponent } from '../common/src/index';
import config from '../common/config';
import props from './props';
import { getCharacterLength, calcIcon } from '../common/utils';
import { getCharacterLength, calcIcon, isDef } from '../common/utils';
const { prefix } = config;
const name = `${prefix}-input`;
let Input = class Input extends SuperComponent {
@@ -32,11 +32,13 @@
            prefix,
            classPrefix: name,
            classBasePrefix: prefix,
            showClearIcon: true,
        };
        this.lifetimes = {
            ready() {
                const { value } = this.properties;
                this.updateValue(value == null ? '' : value);
                var _a;
                const { value, defaultValue } = this.properties;
                this.updateValue((_a = value !== null && value !== void 0 ? value : defaultValue) !== null && _a !== void 0 ? _a : '');
            },
        };
        this.observers = {
@@ -55,6 +57,9 @@
                    _clearIcon: calcIcon(v, 'close-circle-filled'),
                });
            },
            clearTrigger() {
                this.updateClearIconVisible();
            },
        };
        this.methods = {
            updateValue(value) {
@@ -66,7 +71,7 @@
                        count: length,
                    });
                }
                else if (maxlength > 0 && !Number.isNaN(maxlength)) {
                else if (maxlength && maxlength > 0 && !Number.isNaN(maxlength)) {
                    const { length, characters } = getCharacterLength('maxlength', value, maxlength);
                    this.setData({
                        value: characters,
@@ -76,9 +81,13 @@
                else {
                    this.setData({
                        value,
                        count: value ? String(value).length : 0,
                        count: isDef(value) ? String(value).length : 0,
                    });
                }
            },
            updateClearIconVisible(value = false) {
                const { clearTrigger } = this.properties;
                this.setData({ showClearIcon: value || clearTrigger === 'always' });
            },
            onInput(e) {
                const { value, cursor, keyCode } = e.detail;
@@ -86,9 +95,11 @@
                this.triggerEvent('change', { value: this.data.value, cursor, keyCode });
            },
            onFocus(e) {
                this.updateClearIconVisible(true);
                this.triggerEvent('focus', e.detail);
            },
            onBlur(e) {
                this.updateClearIconVisible();
                this.triggerEvent('blur', e.detail);
            },
            onConfirm(e) {