浏览代码

feat(a11y): typogarphy aria #205

走鹃 3 年之前
父节点
当前提交
f7c58023cd
共有 2 个文件被更改,包括 17 次插入2 次删除
  1. 7 1
      packages/semi-ui/typography/base.tsx
  2. 10 1
      packages/semi-ui/typography/copyable.tsx

+ 7 - 1
packages/semi-ui/typography/base.tsx

@@ -11,6 +11,7 @@ import Tooltip from '../tooltip/index';
 import Popover from '../popover/index';
 import Popover from '../popover/index';
 import getRenderText from './util';
 import getRenderText from './util';
 import warning from '@douyinfe/semi-foundation/utils/warning';
 import warning from '@douyinfe/semi-foundation/utils/warning';
+import isEnterPress from '@douyinfe/semi-foundation/utils/isEnterPress';
 import LocaleConsumer from '../locale/localeConsumer';
 import LocaleConsumer from '../locale/localeConsumer';
 import { Locale } from '../locale/interface';
 import { Locale } from '../locale/interface';
 import { Ellipsis, EllipsisPos, ShowTooltip, TypographyBaseSize, TypographyBaseType } from './interface';
 import { Ellipsis, EllipsisPos, ShowTooltip, TypographyBaseSize, TypographyBaseType } from './interface';
@@ -372,13 +373,18 @@ export default class Base extends Component<BaseTypographyProps, BaseTypographyS
         }
         }
         if (!noExpandText || !noCollapseText) {
         if (!noExpandText || !noCollapseText) {
             return (
             return (
+                // TODO: replace `a` tag with `span` in next major version
+                // NOTE: may have effect on style
+                // eslint-disable-next-line jsx-a11y/anchor-is-valid
                 <a
                 <a
+                    role="button"
+                    tabIndex={0}
                     className={`${prefixCls}-ellipsis-expand`}
                     className={`${prefixCls}-ellipsis-expand`}
                     key="expand"
                     key="expand"
                     ref={this.expandRef}
                     ref={this.expandRef}
                     aria-label={text}
                     aria-label={text}
                     onClick={this.toggleOverflow}
                     onClick={this.toggleOverflow}
-                    // style={{ marginLeft: '8px' }}
+                    onKeyPress={e => isEnterPress(e) && this.toggleOverflow(e as any)}
                 >
                 >
                     {text}
                     {text}
                 </a>
                 </a>

+ 10 - 1
packages/semi-ui/typography/copyable.tsx

@@ -9,6 +9,7 @@ import LocaleConsumer from '../locale/localeConsumer';
 import { IconCopy, IconTick } from '@douyinfe/semi-icons';
 import { IconCopy, IconTick } from '@douyinfe/semi-icons';
 import { BaseProps } from '../_base/baseComponent';
 import { BaseProps } from '../_base/baseComponent';
 import { Locale } from '../locale/interface';
 import { Locale } from '../locale/interface';
+import isEnterPress from '@douyinfe/semi-foundation/utils/isEnterPress';
 
 
 const prefixCls = cssClasses.PREFIX;
 const prefixCls = cssClasses.PREFIX;
 export interface CopyableProps extends BaseProps {
 export interface CopyableProps extends BaseProps {
@@ -120,8 +121,16 @@ export class Copyable extends React.PureComponent<CopyableProps, CopyableState>
                             this.renderSuccessTip()
                             this.renderSuccessTip()
                         ) : (
                         ) : (
                             <Tooltip content={typeof copyTip !== 'undefined' ? copyTip : locale.copy}>
                             <Tooltip content={typeof copyTip !== 'undefined' ? copyTip : locale.copy}>
+                                {/* TODO: replace `a` tag with `span` in next major version
+                                NOTE: may have effect on style */}
+                                {/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
                                 <a className={`${prefixCls}-action-copy-icon`}>
                                 <a className={`${prefixCls}-action-copy-icon`}>
-                                    <IconCopy onClick={this.copy} />
+                                    <IconCopy
+                                        role="button"
+                                        tabIndex={0}
+                                        onClick={this.copy}
+                                        onKeyPress={e => isEnterPress(e) && this.copy(e as any)}
+                                    />
                                 </a>
                                 </a>
                             </Tooltip>
                             </Tooltip>
                         )}
                         )}