Skip to content

Commit

Permalink
Fix(inputitem): add wai-aria suppport for the money type InputItem
Browse files Browse the repository at this point in the history
The money type InputItem is simulated with the div tag, rather than the origin
input tag. To support wai-aria needs a little more work, for the div tag, by adding
role of `textbox` make div perform like input in aria mode

For the CustomKeyboard, it will lead to wrong focus when not adding aria
supoort for backspace and keyboard canceling

Fixed: #2419, #2418
  • Loading branch information
KgTong committed May 13, 2018
1 parent d2171f7 commit 7ccd3bb
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 4 deletions.
14 changes: 13 additions & 1 deletion components/input-item/CustomInput.tsx
Expand Up @@ -20,6 +20,8 @@ export interface NumberInputProps {
onFocus?: InputEventHandler;
onBlur?: InputEventHandler;
confirmLabel: any;
backspaceLabel: any;
cancelKeyboardLabel: any;
maxLength?: number;
type?: string;
style?: React.CSSProperties;
Expand Down Expand Up @@ -88,13 +90,21 @@ class NumberInput extends React.Component<NumberInputProps, any> {
}

getComponent() {
const { keyboardPrefixCls, confirmLabel } = this.props;
const {
confirmLabel,
backspaceLabel,
keyboardPrefixCls,
cancelKeyboardLabel,
} = this.props;

return (
<CustomKeyboard
ref={this.saveRef}
onClick={this.onKeyboardClick}
preixCls={keyboardPrefixCls}
confirmLabel={confirmLabel}
backspaceLabel={backspaceLabel}
cancelKeyboardLabel={cancelKeyboardLabel}
/>
);
}
Expand Down Expand Up @@ -294,6 +304,8 @@ class NumberInput extends React.Component<NumberInputProps, any> {
<div className="fake-input-placeholder">{placeholder}</div>
)}
<div
role="textbox"
aria-label={value || placeholder}
className={fakeInputCls}
ref={el => (this.inputRef = el)}
onClick={preventKeyboard ? () => {} : this.onFakeInputClick}
Expand Down
11 changes: 10 additions & 1 deletion components/input-item/CustomKeyboard.tsx
Expand Up @@ -96,7 +96,12 @@ class CustomKeyboard extends React.Component<any, any> {
);
}
render() {
const { prefixCls, confirmLabel } = this.props;
const {
prefixCls,
confirmLabel,
backspaceLabel,
cancelKeyboardLabel,
} = this.props;

const wrapperCls = classnames(
`${prefixCls}-wrapper`,
Expand All @@ -113,6 +118,8 @@ class CustomKeyboard extends React.Component<any, any> {
this.renderKeyboardItem(item, index),
)}
<KeyboardItem
role="button"
aria-label={backspaceLabel}
className="keyboard-delete"
rowSpan={2}
onClick={this.onKeyboardClick}
Expand Down Expand Up @@ -144,6 +151,8 @@ class CustomKeyboard extends React.Component<any, any> {
this.renderKeyboardItem(item, index),
)}
<KeyboardItem
role="button"
aria-label={cancelKeyboardLabel}
className="keyboard-hide"
onClick={this.onKeyboardClick}
/>
Expand Down
13 changes: 11 additions & 2 deletions components/input-item/index.tsx
Expand Up @@ -224,9 +224,16 @@ class InputItem extends React.Component<InputItemProps, any> {
() => require('./locale/zh_CN'),
);

const { confirmLabel } = _locale;
const {
focus,
placeholder,
} = this.state;

const { placeholder, focus } = this.state;
const {
confirmLabel,
backspaceLabel,
cancelKeyboardLabel,
} = _locale;

const wrapCls = classnames(
`${prefixListCls}-item`,
Expand Down Expand Up @@ -297,6 +304,8 @@ class InputItem extends React.Component<InputItemProps, any> {
prefixCls={prefixCls}
style={style}
confirmLabel={confirmLabel}
backspaceLabel={backspaceLabel}
cancelKeyboardLabel={cancelKeyboardLabel}
moneyKeyboardAlign={moneyKeyboardAlign}
/>
) : (
Expand Down
2 changes: 2 additions & 0 deletions components/input-item/locale/en_US.tsx
@@ -1,3 +1,5 @@
export default {
confirmLabel: 'Done',
backspaceLabel: 'Backspace',
cancelKeyboardLabel: 'CancelKeyboard',
};
2 changes: 2 additions & 0 deletions components/input-item/locale/ru_RU.tsx
@@ -1,3 +1,5 @@
export default {
confirmLabel: 'сделанный',
backspaceLabel: 'возврат на одну позицию',
cancelKeyboardLabel: 'Отменить клавиатуру',
};
2 changes: 2 additions & 0 deletions components/input-item/locale/sv_SE.tsx
@@ -1,3 +1,5 @@
export default {
confirmLabel: 'Ok',
backspaceLabel: 'Backspace',
cancelKeyboardLabel: 'CancelKeyboard',
};
2 changes: 2 additions & 0 deletions components/input-item/locale/zh_CN.tsx
@@ -1,3 +1,5 @@
export default {
confirmLabel: '确定',
backspaceLabel: '退格',
cancelKeyboardLabel: '撤销键盘',
};

0 comments on commit 7ccd3bb

Please sign in to comment.