Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/drawer draggable #1135

Merged
merged 3 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/drawer/demos/placement.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
:onOverlayClick="() => (visible = false)"
:onConfirm="() => (visible = false)"
:placement="placement"
:sizeDraggable="true"
>
<p>抽屉的内容</p>
</t-drawer>
Expand Down
43 changes: 43 additions & 0 deletions examples/drawer/demos/size-draggable.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<template>
<div>
<!-- @click-cancel 和 :onClickCancel 两种写法都支持; :onClickOverlay 和 @click-overlay 两种写法都支持-->
<t-drawer
header="抽屉标题"
:visible="visible"
@cancel="visible = false"
:onOverlayClick="() => (visible = false)"
:onConfirm="() => (visible = false)"
:placement="placement"
:sizeDraggable="true"
>
<p>抽屉的内容</p>
</t-drawer>
<div class="tdesign-radio-button">
<t-radio-group :defaultValue="placement" v-model="placement">
<t-radio-button value="left">从左侧拖拽抽屉</t-radio-button>
<t-radio-button value="right">从右侧拖拽抽屉</t-radio-button>
<t-radio-button value="top">从上方拖拽抽屉</t-radio-button>
<t-radio-button value="bottom">从下方拖拽抽屉</t-radio-button>
</t-radio-group>
</div>
<t-button variant="outline" @click="visible = true" class="btn-top-margin">打开抽屉</t-button>
</div>
</template>

<script>
import Vue from 'vue';

export default Vue.extend({
data() {
return {
visible: false,
placement: 'right',
};
},
});
</script>
<style scoped>
.btn-top-margin {
margin-top: 16px;
}
</style>
2 changes: 1 addition & 1 deletion src/_common
20 changes: 8 additions & 12 deletions src/drawer/drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,24 +163,23 @@ export default mixins(ActionMixin, getConfigReceiverMixins<Vue, DrawerConfig>('d
{this.footer !== false ? (
<div class={`${name}__footer`}>{renderTNodeJSX(this, 'footer', defaultFooter)}</div>
) : null}
{this.sizeDraggable && (
<div
style={this.draggableLineStyles}
onMousedown={this.enableDrag}
onMousemove={this.handleMousemove}
onMouseup={this.disableDrag}
onMouseleave={this.disableDrag}
></div>
)}
{this.sizeDraggable && <div style={this.draggableLineStyles} onMousedown={this.enableDrag}></div>}
</div>
</div>
);
},

methods: {
enableDrag() {
document.addEventListener('mouseup', this.handleMouseup, true);
document.addEventListener('mousemove', this.handleMousemove, true);
this.isSizeDragging = true;
},
handleMouseup() {
document.removeEventListener('mouseup', this.handleMouseup, true);
document.removeEventListener('mousemove', this.handleMousemove, true);
this.isSizeDragging = false;
},
handleMousemove(e: MouseEvent) {
const { x, y } = e;
if (this.isSizeDragging && this.sizeDraggable) {
Expand All @@ -198,9 +197,6 @@ export default mixins(ActionMixin, getConfigReceiverMixins<Vue, DrawerConfig>('d
}
}
},
disableDrag() {
this.isSizeDragging = false;
},
handleScrollThrough(visible: boolean) {
if (!document || !document.body || !this.preventScrollThrough) return;
if (visible && !this.showInAttachedElement) {
Expand Down
22 changes: 21 additions & 1 deletion test/ssr/__snapshots__/ssr.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5789,7 +5789,6 @@ exports[`ssr snapshot test renders ./examples/drawer/demos/placement.vue correct
<div class="t-drawer__footer">
<div style="display:flex;justify-content:flex-start;"><button type="button" class="t-button t-size-m t-button--variant-base t-button--theme-primary t-drawer__confirm"><span class="t-button__text">确认</span></button><button type="button" class="t-button t-size-m t-button--variant-base t-button--theme-default t-drawer__cancel"><span class="t-button__text">取消</span></button></div>
</div>
<div style="z-index:1;position:absolute;background:transparent;left:0;width:16px;height:100%;cursor:col-resize;"></div>
</div>
</div>
<div class="tdesign-radio-button">
Expand Down Expand Up @@ -5839,6 +5838,27 @@ exports[`ssr snapshot test renders ./examples/drawer/demos/size.vue correctly 1`
</div>
`;

exports[`ssr snapshot test renders ./examples/drawer/demos/size-draggable.vue correctly 1`] = `
<div>
<div tabindex="0" class="t-drawer t-drawer--right">
<div class="t-drawer__mask"></div>
<div class="t-drawer__content-wrapper t-drawer__content-wrapper--right" style="width:300px;height:;">
<div class="t-drawer__header">抽屉标题</div>
<div class="t-drawer__body">
<p>抽屉的内容</p>
</div>
<div class="t-drawer__footer">
<div style="display:flex;justify-content:flex-start;"><button type="button" class="t-button t-size-m t-button--variant-base t-button--theme-primary t-drawer__confirm"><span class="t-button__text">确认</span></button><button type="button" class="t-button t-size-m t-button--variant-base t-button--theme-default t-drawer__cancel"><span class="t-button__text">取消</span></button></div>
</div>
<div style="z-index:1;position:absolute;background:transparent;left:0;width:16px;height:100%;cursor:col-resize;"></div>
</div>
</div>
<div class="tdesign-radio-button">
<div class="t-radio-group t-size-m t-radio-group__outline"><label class="t-radio-button"><input type="radio" value="left" name="" class="t-radio-button__former"><span class="t-radio-button__input"></span><span class="t-radio-button__label">从左侧拖拽抽屉</span></label> <label class="t-radio-button t-is-checked"><input type="radio" checked="checked" value="right" name="" class="t-radio-button__former"><span class="t-radio-button__input"></span><span class="t-radio-button__label">从右侧拖拽抽屉</span></label> <label class="t-radio-button"><input type="radio" value="top" name="" class="t-radio-button__former"><span class="t-radio-button__input"></span><span class="t-radio-button__label">从上方拖拽抽屉</span></label> <label class="t-radio-button"><input type="radio" value="bottom" name="" class="t-radio-button__former"><span class="t-radio-button__input"></span><span class="t-radio-button__label">从下方拖拽抽屉</span></label></div>
</div> <button type="button" class="btn-top-margin t-button t-size-m t-button--variant-outline t-button--theme-default"><span class="t-button__text">打开抽屉</span></button>
</div>
`;

exports[`ssr snapshot test renders ./examples/dropdown/demos/base.vue correctly 1`] = `
<div class="tdesign-demo-dropdown"><button type="button" class="t-button t-size-m t-button--variant-text t-button--theme-default"><span class="t-button__text"><span class="tdesign-demo-dropdown__text">
下拉菜单
Expand Down
3 changes: 0 additions & 3 deletions test/unit/drawer/__snapshots__/demo.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -823,9 +823,6 @@ exports[`Drawer Drawer placementVue demo works fine 1`] = `
</button>
</div>
</div>
<div
style="z-index: 1; position: absolute; background: transparent; left: 0px; width: 16px; height: 100%; cursor: col-resize;"
/>
</div>
</div>

Expand Down