Skip to content

Commit 068b3ad

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

File tree

7 files changed

+262
-30
lines changed

7 files changed

+262
-30
lines changed

examples/docs/en-US/drawer.md

+47-4
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

+48-5
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,37 @@ Llamada de un drawer temporal, desde varias direcciones
5050
```
5151
:::
5252

53-
### Personalizar el contenido
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
Al igual que `Dialog`, `Drawer` puede hacer muchas interacciones diversas.
5686

@@ -92,7 +122,7 @@ Al igual que `Dialog`, `Drawer` puede hacer muchas interacciones diversas.
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 @@ Si la variable `visible` se gestiona en el almacén de Vuex, el `.sync` no puede
238280
| 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 |||
239281
| visible | Si se muestra el Drawer, también soporta la notación `.sync` | boolean || false |
240282
| 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 |
241284

242285
### Drawer Slot's
243286

examples/docs/fr-FR/drawer.md

+47-4
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

+48-4
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)