Skip to content

Commit

Permalink
When form layout is vertical, keep the colon inside label, close ant-…
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 authored Jan 13, 2017
1 parent 6a073c8 commit 3423d27
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 10 additions & 0 deletions components/form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ export default class Form extends React.Component<FormProps, any> {
onSubmit: React.PropTypes.func,
};

static childContextTypes = {
vertical: PropTypes.bool,
};

static Item = FormItem;

static create = (options?: FormCreateOption): ComponentDecorator => {
Expand Down Expand Up @@ -153,6 +157,12 @@ export default class Form extends React.Component<FormProps, any> {
return PureRenderMixin.shouldComponentUpdate.apply(this, args);
}

getChildContext() {
return {
vertical: this.props.vertical,
};
}

render() {
const { prefixCls, className = '', inline, horizontal, vertical } = this.props;
const formClassName = classNames(prefixCls, {
Expand Down
9 changes: 7 additions & 2 deletions components/form/FormItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface FormItemProps {

export interface FormItemContext {
form: WrappedFormUtils;
vertical: boolean;
}

export default class FormItem extends React.Component<FormItemProps, any> {
Expand All @@ -55,6 +56,7 @@ export default class FormItem extends React.Component<FormItemProps, any> {

static contextTypes = {
form: React.PropTypes.object,
vertical: React.PropTypes.bool,
};

context: FormItemContext;
Expand Down Expand Up @@ -212,16 +214,19 @@ export default class FormItem extends React.Component<FormItemProps, any> {

renderLabel() {
const props = this.props;
const context = this.context;
const labelCol = props.labelCol;
const required = this.isRequired();

const className = classNames({
[`${props.prefixCls}-item-required`]: required,
});

// remove user input colon
let label = props.label;
if (typeof label === 'string' && (label as string).trim() !== '') {
// Keep label is original where there should have no colon
const haveColon = props.colon && !context.vertical;
// Remove duplicated user input colon
if (haveColon && typeof label === 'string' && (label as string).trim() !== '') {
label = (props.label as string).replace(/[:|:]\s*$/, '');
}

Expand Down

0 comments on commit 3423d27

Please sign in to comment.