Page 1 of 1

smartUi FieId组件的type为number时,focus设置不生效

Posted: 2025年 Oct 21日 10:15
by wdd

import React, { useState, useRef } from 'react';
import { View, navigateBack } from '@ray-js/ray';
import { NavBar, Field } from '@ray-js/smart-ui';
import { NoticeTip } from '@/components';
import styles from './index.module.less';

export function Password(props) {
const { query } = props.location;
const noticeTipRef = useRef(null);
const [focusIndex, setFocusIndex] = useState(0);
const [password, setPassword] = useState(['', '', '', '']);

const onClickLeft = () => {
navigateBack();
};

const handleInputChange = (e, index) => {
const value = e.detail;
const filtered = value.replace(/[0-9]/g, '');
if (filtered) {
setFocusIndex(index + 1);
}
setPassword(prev => {
const newArray = [...prev];
newArray[index] = filtered;
return newArray;
});
};

return (
<>
<NavBar
title="密码"
leftArrow
onClickLeft={onClickLeft}
custom-class={styles['nav-bar']}
placeholder
fixed
border={false}
/>
<NoticeTip ref={noticeTipRef} />
<View>{JSON.stringify(password)}</View>
<View className={styles.container}>
<View className={styles.body}>
{password.map((item, index) => (
<View key={index} className={styles['input-box']}>
<Field
value={item}
focus={focusIndex === index}
type="number"
hiddenLabel
label=""
placeholder=""
inputAlign="center"
maxlength={1}
onInput={e => handleInputChange(e, index)}
center
holdKeyboard
disableDefaultPadding
/>
</View>
))}
</View>
</View>
</>
);
}

export default Password;


Re: smartUi FieId组件的type为number时,focus设置不生效

Posted: 2025年 Oct 23日 09:52
by xiaoqi

目前小程序原生不支持自动 focus ,后续这些属性会下掉


Re: smartUi FieId组件的type为number时,focus设置不生效

Posted: 2025年 Nov 21日 17:55
by 18559697016

Code: Select all

                <Field
                  value={timeValue}
                  placeholder="10"
                  placeholderStyle={{ color: '#0074FF', fontSize: '15px' }}
                  onChange={handleTimeValueChange}
                  inputAlign='center'
                  adjustPosition={false}
                  hiddenLabel={true}
                  className={styles.inputStyle}
                  type='number'
                  customStyle={{
                    color: '#FFFFFF',
                    fontSize: '15px',
                    display: 'flex',
                    flexDirection: 'row',
                    backgroundColor: 'black',
                    height: '40px',
                    borderRadius: '20px',
                    alignItems: 'center',
                    justifyContent: 'center',
                    minHeight: '40px',
                    maxHeight: '40px',
                    overflow: 'hidden',
                    width: '95px',
                    marginLeft: '8px',
                  }}
                />

iOS真机上面。会出现问题。 Field获取焦点以后,整个界面会向上移动,键盘弹出。点击Done后,键盘收起后,整个界面也不会退回来,导致导航栏显示不全。具体看附件。

IMG_DB0F363B1FAA-1.jpeg
IMG_1534.PNG
导航.png

Re: smartUi FieId组件的type为number时,focus设置不生效

Posted: 2025年 Nov 21日 17:58
by xiaoqi

需要 index.config.ts 内设置 disableScroll: false 否则会无法滚动回来 这个后续基础库会修复 但是目前暂时只能这么处理


Re: smartUi FieId组件的type为number时,focus设置不生效

Posted: 2025年 Nov 21日 18:13
by 18559697016

已配置了
还是有bug

ts.png
IMG_0291F08ECC0D-1.jpeg