diff --git a/docs/input/demo/inner.md b/docs/input/demo/inner.md index d056844a2b..202bc9aaaa 100644 --- a/docs/input/demo/inner.md +++ b/docs/input/demo/inner.md @@ -39,7 +39,7 @@ class App extends React.Component { return (
} + innerBefore={} placeholder="search" value={this.state.v} aria-label="input with config of innerBefore" @@ -47,7 +47,7 @@ class App extends React.Component { />

} + innerAfter={} placeholder="search" value={this.state.v} aria-label="input with config of innerAfter" @@ -57,7 +57,7 @@ class App extends React.Component { } + innerAfter={} aria-label="input with config of innerAfter and disabled" />
); } diff --git a/src/input/base.jsx b/src/input/base.jsx index 2e67eb1ae7..2f8aa2e7c7 100644 --- a/src/input/base.jsx +++ b/src/input/base.jsx @@ -6,9 +6,6 @@ import zhCN from '../locale/zh-cn'; class Base extends React.Component { static propTypes = { - /** - * 样式前缀 - */ prefix: PropTypes.string, /** * 当前值 @@ -89,6 +86,7 @@ class Base extends React.Component { * name */ name: PropTypes.string, + rtl: PropTypes.bool, state: PropTypes.oneOf(['error', 'loading', 'success']), locale: PropTypes.object, }; @@ -180,7 +178,7 @@ class Base extends React.Component { } renderLength() { - const { maxLength, hasLimitHint, prefix } = this.props; + const { maxLength, hasLimitHint, prefix, rtl } = this.props; const len = maxLength > 0 && this.state.value ? this.getValueLength(this.state.value) : 0; const classesLenWrap = classNames({ @@ -188,7 +186,9 @@ class Base extends React.Component { [`${prefix}error`]: len > maxLength }); - return maxLength && hasLimitHint ? {len}/{maxLength} : null; + const content = rtl ? `${maxLength}/${len}` : `${len}/${maxLength}`; + + return maxLength && hasLimitHint ? {content} : null; } renderControl() { diff --git a/src/input/group.jsx b/src/input/group.jsx index 3f64678a03..4352fafb7e 100644 --- a/src/input/group.jsx +++ b/src/input/group.jsx @@ -31,6 +31,10 @@ class Group extends React.Component { * 输入框后额外css */ addonAfterClassName: PropTypes.string, + /** + * rtl + */ + rtl: PropTypes.bool, }; static defaultProps = { @@ -38,7 +42,7 @@ class Group extends React.Component { }; render() { - const {className, style, children, prefix, addonBefore, addonAfter, addonBeforeClassName, addonAfterClassName, ...others} = this.props; + const {className, style, children, prefix, addonBefore, addonAfter, addonBeforeClassName, addonAfterClassName, rtl, ...others} = this.props; const cls = classNames({ [`${prefix}input-group`]: true, @@ -68,7 +72,7 @@ class Group extends React.Component { ) : null; return ( - + {before} {children} {after} diff --git a/src/input/input.jsx b/src/input/input.jsx index 572c76ef53..0494058beb 100644 --- a/src/input/input.jsx +++ b/src/input/input.jsx @@ -207,7 +207,7 @@ export default class Input extends Base { } render() { - const {size, htmlType, htmlSize, autoComplete, autoFocus, disabled, style, innerBefore, innerAfter, innerBeforeClassName, innerAfterClassName, className, hasBorder, prefix, addonBefore, addonAfter, addonTextBefore, addonTextAfter, inputRender} = this.props; + const {size, htmlType, htmlSize, autoComplete, autoFocus, disabled, style, innerBefore, innerAfter, innerBeforeClassName, innerAfterClassName, className, hasBorder, prefix, addonBefore, addonAfter, addonTextBefore, addonTextAfter, inputRender, rtl} = this.props; const hasAddon = addonBefore || addonAfter || addonTextBefore || addonTextAfter; const cls = classNames(this.getClass(), { @@ -250,7 +250,7 @@ export default class Input extends Base { ref={this.saveRef} />); - const inputWrap = ( + const inputWrap = ( {this.renderInner(innerBefore, innerBeforeCls)} {this.renderLabel()} {inputRender(inputEl)} diff --git a/src/input/main.scss b/src/input/main.scss index f74037ae8a..dae21b4012 100644 --- a/src/input/main.scss +++ b/src/input/main.scss @@ -75,7 +75,7 @@ #{$input-prefix}-len { padding-bottom: 4px; - padding-right: $input-l-icon-padding-right; + padding: $input-l-icon-padding-right; display: block; text-align: right; width: auto; @@ -183,7 +183,8 @@ width: 1%; top: 0; } - > * + * { + + > *:not(:first-child) { padding-left: $s-1; } @@ -333,10 +334,10 @@ padding: 0 $input-addon-padding; &:first-child { - border-right: 0; + border-right-width: 0; } &:last-child { - border-left: 0; + border-left-width: 0; } &.#{$css-prefix}disabled { @@ -359,3 +360,5 @@ } } } + +@import './rtl.scss'; \ No newline at end of file diff --git a/src/input/rtl.scss b/src/input/rtl.scss new file mode 100644 index 0000000000..8ed2bc4cf8 --- /dev/null +++ b/src/input/rtl.scss @@ -0,0 +1,82 @@ +@charset "UTF-8"; + +#{$input-prefix}[dir="rtl"] { + &.#{$css-prefix}small { + @include input-size-rtl($input-s-label-padding-left, $input-s-icon-padding-right); + } + + &.#{$css-prefix}medium { + @include input-size-rtl($input-m-label-padding-left, $input-m-icon-padding-right); + } + + &.#{$css-prefix}large { + @include input-size-rtl($input-l-label-padding-left, $input-l-icon-padding-right); + } + + &#{$input-prefix}-textarea { + #{$input-prefix}-len { + text-align: left; + } + } + + #{$input-prefix}-control { + > *:not(:first-child) { + padding-right: $s-1; + padding-left: 0; + } + } +} +#{$input-prefix}-group[dir="rtl"] { + #{$input-prefix}-group-addon { + + /* stylelint-disable declaration-no-important */ + &:first-child { + border-bottom-left-radius: 0 !important; + border-top-left-radius: 0 !important; + + &.#{$css-prefix}small { + border-bottom-right-radius: $form-element-small-corner !important; + border-top-right-radius: $form-element-small-corner !important; + } + + &.#{$css-prefix}medium { + border-bottom-right-radius: $form-element-medium-corner !important; + border-top-right-radius: $form-element-medium-corner !important; + } + + &.#{$css-prefix}large { + border-bottom-right-radius: $form-element-large-corner !important; + border-top-right-radius: $form-element-large-corner !important; + } + } + &:last-child { + border-bottom-right-radius: 0 !important; + border-top-right-radius: 0 !important; + + &.#{$css-prefix}small { + border-bottom-left-radius: $form-element-small-corner !important; + border-top-left-radius: $form-element-small-corner !important; + } + + &.#{$css-prefix}medium { + border-bottom-left-radius: $form-element-medium-corner !important; + border-top-left-radius: $form-element-medium-corner !important; + } + + &.#{$css-prefix}large { + border-bottom-left-radius: $form-element-large-corner !important; + border-top-left-radius: $form-element-large-corner !important; + } + } + } + #{$input-prefix}-group-text { + &:first-child { + border-right-width: $input-border-width; + border-left: 0; + } + &:last-child { + border-left-width: $input-border-width; + border-right: 0; + } + } +} diff --git a/src/input/scss/mixin.scss b/src/input/scss/mixin.scss index 9c374b628c..8ec84b377f 100755 --- a/src/input/scss/mixin.scss +++ b/src/input/scss/mixin.scss @@ -40,6 +40,21 @@ } } + +@mixin input-size-rtl( + $labelPadding, + $iconPadding +) { + #{$input-prefix}-label { + padding-left: 0; + padding-right: $labelPadding; + } + #{$input-prefix}-control { + padding-right: 0; + padding-left: $iconPadding; + } +} + @mixin input-border-radius($size) { border-radius: $size; input { diff --git a/src/input/textarea.jsx b/src/input/textarea.jsx index 36e9cd123e..c839bad0d8 100644 --- a/src/input/textarea.jsx +++ b/src/input/textarea.jsx @@ -179,7 +179,7 @@ export default class TextArea extends Base { } render() { - const {rows, style, className, autoHeight, prefix} = this.props; + const {rows, style, className, autoHeight, prefix, rtl} = this.props; const cls = classNames(this.getClass(), { [`${prefix}input-textarea`]: true, @@ -207,7 +207,7 @@ export default class TextArea extends Base { position: 'relative', } : style; - return ( + return (