Skip to content

Commit

Permalink
fix(VTabs): allow proper adjustment of sldier size
Browse files Browse the repository at this point in the history
fixes #8014
  • Loading branch information
johnleider committed Jul 25, 2019
1 parent ce27c73 commit c31b01d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/docs/src/lang/en/components/Tabs.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"right": "Aligns tabs to the right",
"showArrows": "Show pagination arrows if the tab items overflow their container. For mobile devices, arrows will only display when using this prop.",
"sliderColor": "Changes the background color of an auto-generated `v-tabs-slider`",
"sliderSize": "Changes the size of the slider, **height** for horizontal, **width** for vertical.",
"touchless": "Components.NavigationDrawers.props.touchless",
"transition": "Mixins.Transitionable.props.transition",
"vertical": "Stacks tabs on top of each other vertically."
Expand Down
2 changes: 1 addition & 1 deletion packages/vuetify/src/components/VTabs/VTabs.sass
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@

.v-tabs-slider
background-color: currentColor
height: $tabs-slider-height
height: 100%
width: 100%

&-wrapper
Expand Down
8 changes: 6 additions & 2 deletions packages/vuetify/src/components/VTabs/VTabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export default baseMixins.extend<options>().extend({
right: Boolean,
showArrows: Boolean,
sliderColor: String,
sliderSize: {
type: [Number, String],
default: 2,
},
vertical: Boolean,
},

Expand Down Expand Up @@ -167,11 +171,11 @@ export default baseMixins.extend<options>().extend({
const el = activeTab.$el as HTMLElement

this.slider = {
height: this.vertical ? el.offsetHeight : 2,
height: !this.vertical ? Number(this.sliderSize) : el.scrollHeight,
left: this.vertical ? 0 : el.offsetLeft,
right: this.vertical ? 0 : el.offsetLeft + el.offsetWidth,
top: el.offsetTop,
width: this.vertical ? 2 : el.scrollWidth,
width: this.vertical ? Number(this.sliderSize) : el.scrollWidth,
}
})

Expand Down
35 changes: 35 additions & 0 deletions packages/vuetify/src/components/VTabs/__tests__/VTabs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,39 @@ describe('VTabs.ts', () => {
expect(wrapper.vm.slider.left).toBe(0)
expect(wrapper.vm.slider.width).toBe(0)
})

it('should adjust slider size', async () => {
const el = {
$el: {
scrollHeight: 99,
scrollWidth: 99,
},
}
const wrapper = mountFunction({
propsData: {
value: 0,
},
})
wrapper.vm.$refs.items.items.push(el)
wrapper.vm.callSlider()

await wrapper.vm.$nextTick()

expect(wrapper.vm.slider.height).toBe(2)

wrapper.setProps({ sliderSize: 4 })
wrapper.vm.callSlider()

await wrapper.vm.$nextTick()

expect(wrapper.vm.slider.height).toBe(4)

wrapper.setProps({ vertical: true })
wrapper.vm.callSlider()

await wrapper.vm.$nextTick()

expect(wrapper.vm.slider.height).toBe(99)
expect(wrapper.vm.slider.width).toBe(4)
})
})
1 change: 0 additions & 1 deletion packages/vuetify/src/components/VTabs/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ $tabs-item-max-width: 360px !default;
$tabs-item-padding: 0 16px !default;
$tabs-item-hover-opacity: 0.16 !default;
$tabs-item-focus-opacity: 0.20 !default;
$tabs-slider-height: 2px !default;
$tabs-item-vertical-height: $tabs-bar-height !default;
$tabs-item-vertical-icons-and-text-height: $tabs-icons-and-text-bar-height !default;

0 comments on commit c31b01d

Please sign in to comment.