From aa4606cd9f67b1435f47a2c14da2eaa0d221f659 Mon Sep 17 00:00:00 2001 From: Benjy Cui Date: Wed, 15 Mar 2017 11:25:58 +0800 Subject: [PATCH] feat: make Form.Item work with responsive layout, ref: #5296 (#5306) --- .../__tests__/__snapshots__/demo.test.js.snap | 90 +++++++++---------- components/form/demo/dynamic-form-item.md | 15 +++- components/form/demo/register.md | 20 ++++- components/form/demo/time-related-controls.md | 15 +++- components/form/demo/validate-static.md | 38 +++++--- components/form/style/index.less | 33 ++++++- 6 files changed, 141 insertions(+), 70 deletions(-) diff --git a/components/form/__tests__/__snapshots__/demo.test.js.snap b/components/form/__tests__/__snapshots__/demo.test.js.snap index fe7847fe0..b1a74e7d7 100644 --- a/components/form/__tests__/__snapshots__/demo.test.js.snap +++ b/components/form/__tests__/__snapshots__/demo.test.js.snap @@ -388,7 +388,7 @@ exports[`test renders ./components/form/demo/dynamic-form-item.md correctly 1`]
+ class="ant-form-item-control-wrapper ant-col-xs-24 ant-col-xs-offset-0 ant-col-sm-20 ant-col-sm-offset-4">
diff --git a/components/form/demo/validate-static.md b/components/form/demo/validate-static.md index 1ba1ab64a..b67f0bca3 100644 --- a/components/form/demo/validate-static.md +++ b/components/form/demo/validate-static.md @@ -25,12 +25,22 @@ We provide properties like `validateStatus` `help` `hasFeedback` to customize yo import { Form, Input, DatePicker, Col } from 'antd'; const FormItem = Form.Item; +const formItemLayout = { + labelCol: { + xs: { span: 24 }, + sm: { span: 5 }, + }, + wrapperCol: { + xs: { span: 24 }, + sm: { span: 12 }, + }, +}; + ReactDOM.render(
@@ -38,18 +48,16 @@ ReactDOM.render( @@ -68,9 +75,8 @@ ReactDOM.render( @@ -78,9 +84,8 @@ ReactDOM.render( diff --git a/components/form/style/index.less b/components/form/style/index.less index 347527842..8cab4e1c4 100644 --- a/components/form/style/index.less +++ b/components/form/style/index.less @@ -249,8 +249,7 @@ form { // Form layout //== Vertical Form -.@{form-prefix-cls}-vertical .@{form-prefix-cls}-item-label, -.@{ant-prefix}-col-24.@{form-prefix-cls}-item-label { // when labelCol is 24, it is a vertical form +.make-vertical-layout() { padding: 0 0 8px; display: block; text-align: left; @@ -259,6 +258,36 @@ form { content: ''; } } +.@{form-prefix-cls}-vertical .@{form-prefix-cls}-item-label, +// when labelCol is 24, it is a vertical form +.@{ant-prefix}-col-24.@{form-prefix-cls}-item-label, +.@{ant-prefix}-col-xl-24.@{form-prefix-cls}-item-label { + .make-vertical-layout(); +} + +@media (max-width: @screen-xs-max) { + .@{ant-prefix}-col-xs-24.@{form-prefix-cls}-item-label { + .make-vertical-layout(); + } +} + +@media (max-width: @screen-sm-max) { + .@{ant-prefix}-col-sm-24.@{form-prefix-cls}-item-label { + .make-vertical-layout(); + } +} + +@media (max-width: @screen-md-max) { + .@{ant-prefix}-col-md-24.@{form-prefix-cls}-item-label { + .make-vertical-layout(); + } +} + +@media (max-width: @screen-lg-max) { + .@{ant-prefix}-col-lg-24.@{form-prefix-cls}-item-label { + .make-vertical-layout(); + } +} //== Inline Form .@{form-prefix-cls}-inline {