Skip to content

Commit ae40acf

Browse files
jw-fosskchjxxgh
authored andcommitted
Drawer: bugfix/drawer-append-to-body-not-working (ElemeFE#16953)
- 修复了 AppendToBody API 不管用的问题. - 修复了展开动画会出现滚动条的问题 - 新增了一个新的 API `withHeader` 来控制是否显示 Header 栏 - 动画流畅度的一个小改动 - 对应文档的改动 - 对应单元测试的改动
1 parent d74de13 commit ae40acf

File tree

7 files changed

+279
-47
lines changed

7 files changed

+279
-47
lines changed

examples/docs/en-US/drawer.md

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,36 @@ Callout a temporary drawer, from multiple direction
5050
```
5151
:::
5252

53+
### No Title
54+
55+
When you no longer need a title, you can remove title from drawer.
56+
57+
:::demo Set the `withHeader` attribute to **false**, you can remove the title from drawer, thus your drawer can have more space on screen. If you want to be accessible, make sure to set the `title` attribute.
58+
59+
```html
60+
<el-button @click="drawer = true" type="primary" style="margin-left: 16px;">
61+
open
62+
</el-button>
63+
64+
<el-drawer
65+
title="I am the title"
66+
:visible.sync="drawer"
67+
:with-header="false">
68+
<span>Hi there!</span>
69+
</el-drawer>
70+
71+
<script>
72+
export default {
73+
data() {
74+
return {
75+
drawer: false,
76+
};
77+
}
78+
};
79+
</script>
80+
```
81+
:::
82+
5383
### Customization Content
5484

5585
Like `Dialog`, `Drawer` can do many diverse interaction as you wanted.
@@ -92,7 +122,7 @@ Like `Dialog`, `Drawer` can do many diverse interaction as you wanted.
92122
</el-form-item>
93123
</el-form>
94124
<div class="demo-drawer__footer">
95-
<el-button @click="dialog = false">Cancel</el-button>
125+
<el-button @click="cancelForm">Cancel</el-button>
96126
<el-button type="primary" @click="$refs.drawer.closeDrawer()" :loading="loading">{{ loading ? 'Submitting ...' : 'Submit' }}</el-button>
97127
</div>
98128
</div>
@@ -132,20 +162,32 @@ export default {
132162
resource: '',
133163
desc: ''
134164
},
135-
formLabelWidth: '80px'
165+
formLabelWidth: '80px',
166+
timer: null,
136167
};
137168
},
138169
methods: {
139170
handleClose(done) {
171+
if (this.loading) {
172+
return;
173+
}
140174
this.$confirm('Do you want to submit?')
141175
.then(_ => {
142176
this.loading = true;
143-
setTimeout(() => {
144-
this.loading = false;
177+
this.timer = setTimeout(() => {
145178
done();
179+
// animation takes time
180+
setTimeout(() => {
181+
this.loading = false;
182+
}, 400);
146183
}, 2000);
147184
})
148185
.catch(_ => {});
186+
},
187+
cancelForm() {
188+
this.loading = false;
189+
this.dialog = false;
190+
clearTimeout(this.timer);
149191
}
150192
}
151193
}
@@ -238,6 +280,7 @@ If the variable bound to `visible` is managed in Vuex store, the `.sync` can not
238280
| title | Drawer's title, can also be set by named slot, detailed descriptions can be found in the slot form | string |||
239281
| visible | Should Drawer be displayed, also support the `.sync` notation | boolean || false |
240282
| wrapperClosable | Indicates whether user can close Drawer by clicking the shadowing layer. | boolean | - | true |
283+
| withHeader | Flag that controls the header section's existance, default to true, when withHeader set to false, both `title attribute` and `title slot` won't work | boolean | - | true |
241284

242285
### Drawer Slot
243286

examples/docs/es/drawer.md

Lines changed: 65 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,37 @@ Callout a temporary drawer, from multiple direction
5050
```
5151
:::
5252

53-
### Customization Content
53+
### No Title
54+
55+
When you no longer need a title, you can remove title from drawer.
56+
57+
:::demo Set the `withHeader` attribute to **false**, you can remove the title from drawer, thus your drawer can have more space on screen. If you want to be accessible, make sure to set the `title` attribute.
58+
59+
```html
60+
<el-button @click="drawer = true" type="primary" style="margin-left: 16px;">
61+
open
62+
</el-button>
63+
64+
<el-drawer
65+
title="I am the title"
66+
:visible.sync="drawer"
67+
:with-header="false">
68+
<span>Hi there!</span>
69+
</el-drawer>
70+
71+
<script>
72+
export default {
73+
data() {
74+
return {
75+
drawer: false,
76+
};
77+
}
78+
};
79+
</script>
80+
```
81+
:::
82+
83+
### Personalizar el contenido
5484

5585
Like `Dialog`, `Drawer` can do many diverse interaction as you wanted.
5686

@@ -92,7 +122,7 @@ Like `Dialog`, `Drawer` can do many diverse interaction as you wanted.
92122
</el-form-item>
93123
</el-form>
94124
<div class="demo-drawer__footer">
95-
<el-button @click="dialog = false">Cancel</el-button>
125+
<el-button @click="cancelForm">Cancel</el-button>
96126
<el-button type="primary" @click="$refs.drawer.closeDrawer()" :loading="loading">{{ loading ? 'Submitting ...' : 'Submit' }}</el-button>
97127
</div>
98128
</div>
@@ -132,20 +162,32 @@ export default {
132162
resource: '',
133163
desc: ''
134164
},
135-
formLabelWidth: '80px'
165+
formLabelWidth: '80px',
166+
timer: null,
136167
};
137168
},
138169
methods: {
139170
handleClose(done) {
171+
if (this.loading) {
172+
return;
173+
}
140174
this.$confirm('Do you want to submit?')
141175
.then(_ => {
142176
this.loading = true;
143-
setTimeout(() => {
144-
this.loading = false;
177+
this.timer = setTimeout(() => {
145178
done();
179+
// animation takes time
180+
setTimeout(() => {
181+
this.loading = false;
182+
}, 400);
146183
}, 2000);
147184
})
148185
.catch(_ => {});
186+
},
187+
cancelForm() {
188+
this.loading = false;
189+
this.dialog = false;
190+
clearTimeout(this.timer);
149191
}
150192
}
151193
}
@@ -225,23 +267,24 @@ If the variable bound to `visible` is managed in Vuex store, the `.sync` can not
225267

226268
| Parameter| Description | Type | Acceptable Values | Defaults |
227269
|---------- |-------------- |---------- |-------------------------------- |-------- |
228-
| append-to-body | Controls should Drawer be inserted to DocumentBody Element, nested Drawer must assign this param to **true**| boolean || false |
229-
| before-close | If set, closing procedure will be halted | function(done), done is function type that accepts a boolean as parameter, calling done with true or without parameter will abort the close procedure |||
230-
| close-on-press-escape | Indicates whether Drawer can be closed by pressing ESC | boolean || true |
231-
| custom-class | Extra class names for Drawer | string |||
232-
| destroy-on-close | Indicates whether children should be destroyed after Drawer closed | boolean | - | false |
233-
| modal | Should show shadowing layer | boolean || true |
234-
| modal-append-to-body | Indicates should shadowing layer be insert into DocumentBody element | boolean || true |
235-
| direction | Drawer's opening direction | Direction | rtl / ltr / ttb / tbb | rtl |
236-
| show-close | Should show close button at the top right of Drawer | boolean || true |
237-
| size | Drawer's size, if Drawer is horizontal mode, it effects the width property, otherwise it effects the height property, when size is `number` type, it describes the size by unit of pixels; when size is `string` type, it should be used with `x%` notation, other wise it will be interpreted to pixel unit | number / string | - | '30%' |
238-
| title | Drawer's title, can also be set by named slot, detailed descriptions can be found in the slot form | string |||
239-
| visible | Should Drawer be displayed, also support the `.sync` notation | boolean || false |
240-
| wrapperClosable | Indicates whether user can close Drawer by clicking the shadowing layer. | boolean | - | true |
241-
242-
### Drawer Slot
243-
244-
| Name | Description |
270+
| append-to-body | Los controles deberían insertar Drawer en el elemento DocumentBody, los Drawer anidados deben asignar este parámetro a **true** | boolean || false |
271+
| before-close | Si está configurado, el procedimiento de cierre se detendrá. | function(done), done es un tipo de función que acepta un booleano como parámetro, una llamada hecha con true o sin parámetro abortará el procedimiento de cierre. |||
272+
| close-on-press-escape | Indica si el Drawer puede cerrarse pulsando ESC | boolean || true |
273+
| custom-class | Nombre extra de clase para Drawer | string |||
274+
| destroy-on-close | Indica si los children deben ser destruidos después de cerrar el Drawer. | boolean | - | false |
275+
| modal | Mostrará una capa de sombra | boolean || true |
276+
| modal-append-to-body | Indica si se debe insertar una capa de sombreado en el elemento DocumentBody | boolean || true |
277+
| direction | Dirección de apertura del Drawer | Direction | rtl / ltr / ttb / btt | rtl |
278+
| show-close | Se mostrará el botón de cerrar en la parte superior derecha del Drawer | boolean || true |
279+
| size | Tamaño del Drawer. Si el Drawer está en modo horizontal, afecta a la propiedad width, de lo contrario afecta a la propiedad height, cuando el tamaño es tipo `number`, describe el tamaño por unidad de píxeles; cuando el tamaño es tipo `string`, se debe usar con notación `x%`, de lo contrario se interpretará como unidad de píxeles. | number / string | - | '30%' |
280+
| title | El título del Drawer, también se puede establecer por slot con nombre, las descripciones detalladas se pueden encontrar en el formulario de slot. | string |||
281+
| visible | Si se muestra el Drawer, también soporta la notación `.sync` | boolean || false |
282+
| wrapperClosable | Indica si el usuario puede cerrar el Drawer haciendo clic en la capa de sombreado. | boolean | - | true |
283+
| withHeader | Flag that controls the header section's existance, default to true, when withHeader set to false, both `title attribute` and `title slot` won't work | boolean | - | true |
284+
285+
### Drawer Slot's
286+
287+
| Nombre | Descripción |
245288
|------|--------|
246289
|| Drawer's Content |
247290
| title | Drawer Title Section |

examples/docs/fr-FR/drawer.md

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,36 @@ Callout a temporary drawer, from multiple direction
5050
```
5151
:::
5252

53+
### No Title
54+
55+
When you no longer need a title, you can remove title from drawer.
56+
57+
:::demo Set the `withHeader` attribute to **false**, you can remove the title from drawer, thus your drawer can have more space on screen. If you want to be accessible, make sure to set the `title` attribute.
58+
59+
```html
60+
<el-button @click="drawer = true" type="primary" style="margin-left: 16px;">
61+
open
62+
</el-button>
63+
64+
<el-drawer
65+
title="I am the title"
66+
:visible.sync="drawer"
67+
:with-header="false">
68+
<span>Hi there!</span>
69+
</el-drawer>
70+
71+
<script>
72+
export default {
73+
data() {
74+
return {
75+
drawer: false,
76+
};
77+
}
78+
};
79+
</script>
80+
```
81+
:::
82+
5383
### Customization Content
5484

5585
Like `Dialog`, `Drawer` can do many diverse interaction as you wanted.
@@ -92,7 +122,7 @@ Like `Dialog`, `Drawer` can do many diverse interaction as you wanted.
92122
</el-form-item>
93123
</el-form>
94124
<div class="demo-drawer__footer">
95-
<el-button @click="dialog = false">Cancel</el-button>
125+
<el-button @click="cancelForm">Cancel</el-button>
96126
<el-button type="primary" @click="$refs.drawer.closeDrawer()" :loading="loading">{{ loading ? 'Submitting ...' : 'Submit' }}</el-button>
97127
</div>
98128
</div>
@@ -132,20 +162,32 @@ export default {
132162
resource: '',
133163
desc: ''
134164
},
135-
formLabelWidth: '80px'
165+
formLabelWidth: '80px',
166+
timer: null,
136167
};
137168
},
138169
methods: {
139170
handleClose(done) {
171+
if (this.loading) {
172+
return;
173+
}
140174
this.$confirm('Do you want to submit?')
141175
.then(_ => {
142176
this.loading = true;
143-
setTimeout(() => {
144-
this.loading = false;
177+
this.timer = setTimeout(() => {
145178
done();
179+
// animation takes time
180+
setTimeout(() => {
181+
this.loading = false;
182+
}, 400);
146183
}, 2000);
147184
})
148185
.catch(_ => {});
186+
},
187+
cancelForm() {
188+
this.loading = false;
189+
this.dialog = false;
190+
clearTimeout(this.timer);
149191
}
150192
}
151193
}
@@ -238,6 +280,7 @@ If the variable bound to `visible` is managed in Vuex store, the `.sync` can not
238280
| title | Drawer's title, can also be set by named slot, detailed descriptions can be found in the slot form | string |||
239281
| visible | Should Drawer be displayed, also support the `.sync` notation | boolean || false |
240282
| wrapperClosable | Indicates whether user can close Drawer by clicking the shadowing layer. | boolean | - | true |
283+
| withHeader | Flag that controls the header section's existance, default to true, when withHeader set to false, both `title attribute` and `title slot` won't work | boolean | - | true |
241284

242285
### Drawer Slot
243286

examples/docs/zh-CN/drawer.md

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,37 @@
5050
```
5151
:::
5252

53+
### 不添加 Title
54+
55+
当你不需要标题到时候, 你还可以去掉标题
56+
57+
:::demo 当遇到不需要 title 的场景时, 可以通过 `withHeader` 这个属性来关闭掉 title 的显示, 这样可以留出更大的空间给到用户, 为了用户的可访问性, 请务必设定 `title` 的值
58+
59+
```html
60+
<el-button @click="drawer = true" type="primary" style="margin-left: 16px;">
61+
点我打开
62+
</el-button>
63+
64+
<el-drawer
65+
title="我是标题"
66+
:visible.sync="drawer"
67+
:with-header="false">
68+
<span>我来啦!</span>
69+
</el-drawer>
70+
71+
<script>
72+
export default {
73+
data() {
74+
return {
75+
drawer: false,
76+
};
77+
}
78+
};
79+
</script>
80+
```
81+
:::
82+
83+
5384
### 自定义内容
5485

5586
`Dialog` 组件一样, `Drawer` 同样可以在其内部嵌套各种丰富的操作
@@ -92,7 +123,7 @@
92123
</el-form-item>
93124
</el-form>
94125
<div class="demo-drawer__footer">
95-
<el-button @click="dialog = false">取 消</el-button>
126+
<el-button @click="cancelForm">取 消</el-button>
96127
<el-button type="primary" @click="$refs.drawer.closeDrawer()" :loading="loading">{{ loading ? '提交中 ...' : '确 定' }}</el-button>
97128
</div>
98129
</div>
@@ -132,20 +163,32 @@ export default {
132163
resource: '',
133164
desc: ''
134165
},
135-
formLabelWidth: '80px'
166+
formLabelWidth: '80px',
167+
timer: null,
136168
};
137169
},
138170
methods: {
139171
handleClose(done) {
172+
if (this.loading) {
173+
return;
174+
}
140175
this.$confirm('确定要提交表单吗?')
141176
.then(_ => {
142177
this.loading = true;
143-
setTimeout(() => {
144-
this.loading = false;
178+
this.timer = setTimeout(() => {
145179
done();
180+
// 动画关闭需要一定的时间
181+
setTimeout(() => {
182+
this.loading = false;
183+
}, 400);
146184
}, 2000);
147185
})
148186
.catch(_ => {});
187+
},
188+
cancelForm() {
189+
this.loading = false;
190+
this.dialog = false;
191+
clearTimeout(this.timer);
149192
}
150193
}
151194
}
@@ -239,6 +282,7 @@ Drawer 提供一个 `destroyOnClose` API, 用来在关闭 Drawer 时销毁子组
239282
| title | Drawer 的标题,也可通过具名 slot (见下表)传入 | string |||
240283
| visible | 是否显示 Drawer,支持 .sync 修饰符 | boolean || false |
241284
| wrapperClosable | 点击遮罩层是否可以关闭 Drawer | boolean | - | true |
285+
| withHeader | 控制是否显示 header 栏, 默认为 true, 当此项为 false 时, title attribute 和 title slot 均不生效 | boolean | - | true |
242286

243287
### Drawer Slot
244288

0 commit comments

Comments
 (0)