Skip to content

Commit

Permalink
fix(table): unexpect horizontal scroll appear
Browse files Browse the repository at this point in the history
fix #278
  • Loading branch information
qmhc committed Mar 8, 2023
1 parent aadf319 commit 84598bf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion components/table/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ export function useStore(options: StoreOptions) {
// 剩余空间有多时, 均分到弹性列
// if (flexColumnCount && flexWidth > flexColumnCount * flexUnitWidth) {
if (flexColumnCount) {
flexUnitWidth = Math.floor(flexWidth / flexColumnCount)
flexUnitWidth = flexWidth / flexColumnCount
}

for (let i = 0; i < flexColumnCount; ++i) {
Expand Down
21 changes: 8 additions & 13 deletions components/table/table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
<slot></slot>
</div>
<Scroll
ref="xScroll"
inherit
use-x-bar
mode="horizontal"
:class="[nh.be('wrapper'), props.scrollClass.horizontal]"
:bar-class="nh.bem('bar', 'horizontal')"
:width="props.width"
:bar-fade="props.barFade"
:delta-x="50"
@scroll="handleXScroll"
Expand Down Expand Up @@ -250,6 +250,7 @@ export default defineComponent({
const yScrollEnable = ref(false)
const wrapper = ref<HTMLElement>()
const xScroll = ref<InstanceType<typeof Scroll>>()
const thead = ref<InstanceType<typeof TableHead>>()
const mainScroll = ref<InstanceType<typeof Scroll>>()
const indicator = ref<HTMLElement>()
Expand Down Expand Up @@ -515,21 +516,14 @@ export default defineComponent({
if (isDefined(width)) {
if (typeof width === 'string' && parseFloat(width).toString() !== width) {
tableWidth.value = width
nextTick(() => {
wrapper.value && setTableWidth(wrapper.value.offsetWidth)
})
} else {
const numberWidth = toNumber(width)
tableWidth.value = `${numberWidth}px`
setTableWidth(numberWidth)
tableWidth.value = `${toNumber(width)}px`
}
} else {
nextTick(() => {
wrapper.value && setTableWidth(wrapper.value.offsetWidth)
})
}
nextTick(() => {
xScroll.value?.$el && setTableWidth(xScroll.value?.$el.offsetWidth)
})
}
function computeBodyHeight() {
Expand Down Expand Up @@ -962,6 +956,7 @@ export default defineComponent({
store,
wrapper,
xScroll,
thead,
mainScroll,
indicator,
Expand Down
2 changes: 2 additions & 0 deletions style/table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ $table: map.merge(
border: $border-a transparent;

&__wrapper {
width: 100%;

.#{$namespace}-scroll__wrapper {
min-width: 100%;
}
Expand Down

0 comments on commit 84598bf

Please sign in to comment.