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(Input): fix auto-width in display: none #1749

Merged
merged 4 commits into from
Nov 8, 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
2 changes: 1 addition & 1 deletion src/_common
19 changes: 19 additions & 0 deletions src/input/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default mixins(getConfigReceiverMixins<InputInstance, InputConfig>('input
inputValue: this.value,
composingRef: false,
composingRefValue: this.value,
resizeObserver: null as ResizeObserver,
};
},
computed: {
Expand Down Expand Up @@ -183,6 +184,15 @@ export default mixins(getConfigReceiverMixins<InputInstance, InputConfig>('input
this.innerStatus && this.onValidateChange();
},

mounted() {
this.addTableResizeObserver(this.$refs.inputPreRef as Element);
},

beforeDestroy() {
this.resizeObserver?.unobserve(this.$refs.inputPreRef as Element);
this.resizeObserver?.disconnect();
},

methods: {
addListeners() {
this.$watch(
Expand All @@ -196,6 +206,15 @@ export default mixins(getConfigReceiverMixins<InputInstance, InputConfig>('input
{ immediate: true },
);
},
// 当元素默认为 display: none 状态,无法提前准确计算宽度,因此需要监听元素宽度变化。比如:Tabs 场景切换。
addTableResizeObserver(element: Element) {
// IE 11 以下使用设置 minWidth 兼容;IE 11 以上使用 ResizeObserver
if (typeof window.ResizeObserver === 'undefined' || !element) return;
this.resizeObserver = new window.ResizeObserver(() => {
this.updateInputWidth();
});
this.resizeObserver.observe(element);
},
mouseEvent(v: boolean) {
this.isHover = v;
},
Expand Down
2 changes: 2 additions & 0 deletions src/pagination/pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import props from './props';
import { ClassName } from '../common';
import { emitEvent } from '../utils/event';
import { TdPaginationProps } from './type';
import { getIEVersion } from '../_common/js/utils/helper';

const min = 1;

Expand Down Expand Up @@ -83,6 +84,7 @@ export default mixins(getConfigReceiverMixins<Vue, PaginationConfig>('pagination
this.commonSizeClassName[this.size],
{
[this.commonStatusClassName.disabled]: this.disabled,
[`${this.componentName}-ie`]: getIEVersion() < 11,
},
];
},
Expand Down