繁体   English   中英

如果用户尝试提交无效信息,如何让屏幕阅读器读出出现的验证错误文本?

[英]How to make screen reader read out a validation error text that appears if the user tries to submit invalid information?

我有一个包含输入的 TextInput 组件和一个仅在出现错误时出现的 HelperText。 我想知道如何才能使屏幕阅读器在元素出现错误文本后读取错误?

        <TextInputBase
            onFocus={(e) => {
                setIsFocused(true);
                onFocus?.(e);
            }}
            onBlur={(e) => {
                setIsFocused(false);
                onBlur?.(e);
            }}
            outlineColor={colors.gray200}
            activeOutlineColor={colors.primary600}
            accessibilityLabel={label}
            label={label}
            error={!!error}
            // Hide the placeholder when the input is focused
            placeholder={isFocused ? undefined : label}
            theme={{ colors: { text: colors.black, placeholder: colors.gray800 } }}
            style={[style, styles.input]}
            {...rest}
        />

        <HelperText
            type="error"
            visible={!!error}
        >
            {error}
        </HelperText>

你可以看看formikyup ,它们真的很强大!

这非常适合小表格或长表格。

希望这可以帮到你!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM