浏览代码

feat(a11y): inputNumber aria #205

走鹃 3 年之前
父节点
当前提交
eb27f5201e
共有 1 个文件被更改,包括 20 次插入1 次删除
  1. 20 1
      packages/semi-ui/inputNumber/index.tsx

+ 20 - 1
packages/semi-ui/inputNumber/index.tsx

@@ -378,6 +378,8 @@ class InputNumber extends BaseComponent<InputNumberProps, InputNumberState> {
         return (
         return (
             <div className={suffixChildrenCls}>
             <div className={suffixChildrenCls}>
                 <span
                 <span
+                    role="button"
+                    tabIndex={-1}
                     className={upClassName}
                     className={upClassName}
                     onMouseDown={notAllowedUp ? noop : this.handleUpClick}
                     onMouseDown={notAllowedUp ? noop : this.handleUpClick}
                     onMouseUp={this.handleMouseUp}
                     onMouseUp={this.handleMouseUp}
@@ -386,6 +388,8 @@ class InputNumber extends BaseComponent<InputNumberProps, InputNumberState> {
                     <IconChevronUp size="extra-small" />
                     <IconChevronUp size="extra-small" />
                 </span>
                 </span>
                 <span
                 <span
+                    role="button"
+                    tabIndex={-1}
                     className={downClassName}
                     className={downClassName}
                     onMouseDown={notAllowedDown ? noop : this.handleDownClick}
                     onMouseDown={notAllowedDown ? noop : this.handleDownClick}
                     onMouseUp={this.handleMouseUp}
                     onMouseUp={this.handleMouseUp}
@@ -434,13 +438,26 @@ class InputNumber extends BaseComponent<InputNumberProps, InputNumberState> {
             keepFocus,
             keepFocus,
             ...rest
             ...rest
         } = this.props;
         } = this.props;
-        const { value } = this.state;
+        const { value, number } = this.state;
 
 
         const inputNumberCls = classnames(className, `${prefixCls}-number`, {
         const inputNumberCls = classnames(className, `${prefixCls}-number`, {
             [`${prefixCls}-number-size-${size}`]: size,
             [`${prefixCls}-number-size-${size}`]: size,
         });
         });
 
 
         const buttons = this.renderButtons();
         const buttons = this.renderButtons();
+        const ariaProps = {
+            'aria-disabled': disabled,
+            step,
+        };
+        if (number) {
+            ariaProps['aria-valuenow'] = number;
+        }
+        if (max !== Infinity) {
+            ariaProps['aria-valuemax'] = max;
+        }
+        if (min !== -Infinity) {
+            ariaProps['aria-valuemin'] = min;
+        }
 
 
         const input = (
         const input = (
             <div
             <div
@@ -451,6 +468,8 @@ class InputNumber extends BaseComponent<InputNumberProps, InputNumberState> {
                 onMouseLeave={e => this.handleInputMouseLeave(e)}
                 onMouseLeave={e => this.handleInputMouseLeave(e)}
             >
             >
                 <Input
                 <Input
+                    role="spinbutton"
+                    {...ariaProps}
                     {...rest}
                     {...rest}
                     size={size}
                     size={size}
                     disabled={disabled}
                     disabled={disabled}