-
Notifications
You must be signed in to change notification settings - Fork 291
feat: 添加组件无障碍功能支持 #3385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat_v3.x_cpp
Are you sure you want to change the base?
feat: 添加组件无障碍功能支持 #3385
Changes from all commits
e9a80b8
2e7cbd2
61863f5
7d0f814
0cdc8f4
30d9fdf
76c0e2f
3ce6c79
9d0911f
7507379
858715d
c8b6c1f
cd4dd52
72a0e64
9954f35
e4f1ed9
66092f4
57ad0d6
01456f9
d32fd32
3af56f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,6 +83,7 @@ | |
| ...rest | ||
| } = { ...defaultProps, ...props } | ||
|
|
||
| const role = 'button' | ||
| const getStyle = useMemo(() => { | ||
| const style: CSSProperties = {} | ||
| if (color) { | ||
|
|
@@ -161,6 +162,8 @@ | |
| className={buttonClassNames} | ||
| style={{ ...getStyle, ...style }} | ||
| onClick={(e) => handleClick(e as any)} | ||
| ariaRole={role} | ||
| ariaDisabled={disabled} | ||
|
Check failure on line 166 in src/packages/button/button.taro.tsx
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 加一个 button.tsx 下的多语言 |
||
| > | ||
| <View className="nut-button-wrap"> | ||
| {loading && <Loading className="nut-icon-loading" />} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ const defaultProps = { | |
| autoStart: true, | ||
| time: 0, | ||
| destroy: false, | ||
| ariaLabel: '倒计时', | ||
| } as WebCountDownProps | ||
|
|
||
| const InternalCountDown: ForwardRefRenderFunction< | ||
|
|
@@ -45,6 +46,7 @@ const InternalCountDown: ForwardRefRenderFunction< | |
| onRestart, | ||
| onUpdate, | ||
| children, | ||
| ariaLabel, | ||
| ...rest | ||
| } = { ...defaultProps, ...props } | ||
| const classPrefix = 'nut-countdown' | ||
|
|
@@ -61,6 +63,11 @@ const InternalCountDown: ForwardRefRenderFunction< | |
| diffTime: 0, // 设置了 startTime 时,与 date.now() 的差异 | ||
| }) | ||
|
|
||
| const [role, setRole] = useState('') | ||
| // ARIA alert提示内容 | ||
| const [alertContent, setAlertContent] = useState('') | ||
| const alertTimerRef = useRef<number>() | ||
|
|
||
| // 时间戳转换 或 获取当前时间的时间戳 | ||
| const getTimeStamp = (timeStr?: string | number) => { | ||
| if (!timeStr) return Date.now() | ||
|
|
@@ -97,6 +104,12 @@ const InternalCountDown: ForwardRefRenderFunction< | |
| stateRef.current.counting = false | ||
| pause() | ||
| onEnd && onEnd() | ||
| setRole('alert') | ||
| setAlertContent(`${ariaLabel}倒计时结束`) | ||
| alertTimerRef.current = window.setTimeout(() => { | ||
| setRole('') | ||
| setAlertContent('') | ||
| }, 3000) | ||
| } | ||
|
|
||
| if (remainTime > 0) { | ||
|
|
@@ -270,6 +283,9 @@ const InternalCountDown: ForwardRefRenderFunction< | |
|
|
||
| const componentWillUnmount = () => { | ||
| destroy && cancelAnimationFrame(stateRef.current.timer) | ||
| if (alertTimerRef.current) { | ||
| clearTimeout(alertTimerRef.current) | ||
| } | ||
| } | ||
|
|
||
| const renderTime = (() => { | ||
|
|
@@ -282,9 +298,10 @@ const InternalCountDown: ForwardRefRenderFunction< | |
| <div | ||
| className={`${classPrefix} ${className}`} | ||
| style={{ ...style }} | ||
| aria-label={ariaLabel} | ||
| {...rest} | ||
| dangerouslySetInnerHTML={{ | ||
| __html: `${renderTime}`, | ||
| __html: `${renderTime}<span style="display:none" role=${role}>${alertContent}</span>`, | ||
| }} | ||
|
Comment on lines
302
to
305
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 存在 XSS 安全风险,建议重构 使用 建议采用更安全的实现方式: 方案一:使用独立的 React 元素(推荐) -<div
- className={`${classPrefix} ${className}`}
- style={{ ...style }}
- aria-label={ariaLabel}
- {...rest}
- dangerouslySetInnerHTML={{
- __html: `${renderTime}<span style="display:none" role=${role}>${alertContent}</span>`,
- }}
-/>
+<div
+ className={`${classPrefix} ${className}`}
+ style={{ ...style }}
+ aria-label={ariaLabel}
+ {...rest}
+>
+ <span dangerouslySetInnerHTML={{ __html: renderTime }} />
+ <span style={{ display: 'none' }} role={role}>
+ {alertContent}
+ </span>
+</div>方案二:如果必须使用 HTML,进行内容转义 import DOMPurify from 'dompurify'
const sanitizedLabel = DOMPurify.sanitize(ariaLabel)基于静态分析工具的提示。 🧰 Tools🪛 ast-grep (0.39.9)[warning] 302-302: Usage of dangerouslySetInnerHTML detected. This bypasses React's built-in XSS protection. Always sanitize HTML content using libraries like DOMPurify before injecting it into the DOM to prevent XSS attacks. (react-unsafe-html-injection) 🤖 Prompt for AI Agents |
||
| /> | ||
| )} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
繁体中文
arithmetic.minus使用了简体字,建议改为「減」整份
zh-TW文案基本采用繁体字,但arithmetic.minus当前为'减'(简体),与同文件如「暫無數據」「視頻」等用字风格不一致。建议改为繁体写法'減',保证整体一致性:Also applies to: 146-149
🤖 Prompt for AI Agents