From 23bcf8e8e377488235dfef2dc5ba48b624db7722 Mon Sep 17 00:00:00 2001 From: kasonyang Date: Wed, 19 Jul 2023 13:32:39 +0800 Subject: [PATCH] =?UTF-8?q?fix(input):=20=E6=97=A0=E6=95=88=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/input/input.tsx | 14 +++++++------- components/input/styles.ts | 16 ++++++++++++---- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/components/input/input.tsx b/components/input/input.tsx index de11f2f..f578337 100644 --- a/components/input/input.tsx +++ b/components/input/input.tsx @@ -10,7 +10,7 @@ import React, { forwardRef, useImperativeHandle, } from 'react'; -import { TextInput, View, Text, TouchableOpacity } from 'react-native'; +import { TextInput, View, Text, TouchableOpacity, Platform } from 'react-native'; import { formatNumber, BasicComponent, ComponentDefaults } from '../utils'; import Icon from '../icon'; @@ -114,7 +114,7 @@ const defaultProps = { rules: [], rows: null, errorMessage: '', - errorMessageAlign: '', + errorMessageAlign: undefined, showWordLimit: false, autofocus: false, slotButton: null, @@ -287,7 +287,7 @@ export const Input: FunctionComponent< SetActive(false); }, 200); let val = event.nativeEvent?.text; - if (maxlength && val.length > Number(maxlength)) { + if (maxlength && val && val.length > Number(maxlength)) { val = val.slice(0, Number(maxlength)); } updateValue(getModelValue(), 'onBlur'); @@ -420,10 +420,10 @@ export const Input: FunctionComponent< disabled && styles.nutInputText_disabled, error && styles.nutInputText_error, ]} - maxLength={maxlength || undefined} + maxLength={maxlength ? Number(maxlength) : undefined} placeholder={placeholder || locale.placeholder} placeholderTextColor={ - error ? theme['$input-required-color'] : '' + error ? theme['$input-required-color'] : undefined } editable={!readonly && !disabled} value={inputValue} @@ -448,10 +448,10 @@ export const Input: FunctionComponent< error && styles.nutInputText_error, ]} // type={inputType(type)} - maxLength={maxlength || undefined} + maxLength={maxlength ? Number(maxlength) : undefined} placeholder={placeholder || locale.placeholder} placeholderTextColor={ - error ? theme['$input-required-color'] : '' + error ? theme['$input-required-color'] : undefined } editable={!readonly && !disabled} value={ diff --git a/components/input/styles.ts b/components/input/styles.ts index a4382ca..b4b5f69 100644 --- a/components/input/styles.ts +++ b/components/input/styles.ts @@ -1,4 +1,4 @@ -import { StyleSheet } from 'react-native'; +import { Platform, StyleSheet } from 'react-native'; import pt from '../utils/pt'; import px from '../utils/px'; @@ -64,14 +64,22 @@ export default (theme: any) => height: pt(48), textAlign: 'left', borderWidth: 0, - outlineWidh: 0, + ...Platform.select({ + web: { + outlineWidth: 0, + } + }), backgroundColor: 'transparent', color: theme['$gray1'], }, nutInputText_disabled: { color: theme['$input-disabled-color'], - backgroundColor: 'none', - cursor: 'not-allowed', + backgroundColor: undefined, + ...Platform.select({ + web: { + cursor: 'not-allowed', + }, + }), opacity: 1, }, nutInputText_error: {