Skip to content

Commit

Permalink
fix(VDataIterator): add missing isMobile property to custom item slot…
Browse files Browse the repository at this point in the history
… scope (#10345)

fixes #8394
fixes #9436

* fix(vdatatable): add isMobile property to custom item slot scop in DataTable and DataIterator

Add possibility to customize 'item' slot in DataTable and DataIterator in mobile view by introducing
isMobile property to be available in the scope.

* test(vdatatable): fix snapshots

Fix test snapshots

* refactor(vdatatable): refactor DataTable and DataIterator isMobile property

Code refactor connected to code multiplication & fix tests

* refactor(vdatatable): space fix

Space fix

* refactor(vdatatable): typo fix

Typo fix

* style(vdatatable): typo fix

Typo fix

* refactor(vdataiterator): code refactor (small review changes)

* style(vdataiterator): typo fix

Typo fix
  • Loading branch information
alicjamusial authored Feb 11, 2020
1 parent 01666a1 commit f4b4f0a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
16 changes: 13 additions & 3 deletions packages/vuetify/src/components/VDataIterator/VDataIterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export default Themeable.extend({
type: Array as PropType<any[]>,
default: () => [],
},
mobileBreakpoint: {
type: [Number, String],
default: 600,
},
singleExpand: Boolean,
loading: [Boolean, String],
noResultsText: {
Expand Down Expand Up @@ -73,6 +77,13 @@ export default Themeable.extend({
selectableItems (): any[] {
return this.internalCurrentItems.filter(item => this.isSelectable(item))
},
isMobile (): boolean {
// Guard against SSR render
// https://github.com/vuetifyjs/vuetify/issues/7410
if (this.$vuetify.breakpoint.width === 0) return false

return this.$vuetify.breakpoint.width < parseInt(this.mobileBreakpoint, 10)
},
},

watch: {
Expand Down Expand Up @@ -192,15 +203,14 @@ export default Themeable.extend({
this.$emit('item-expanded', { item, value })
},
createItemProps (item: any) {
const props = {
return {
item,
select: (v: boolean) => this.select(item, v),
isSelected: this.isSelected(item),
expand: (v: boolean) => this.expand(item, v),
isExpanded: this.isExpanded(item),
isMobile: this.isMobile,
}

return props
},
genEmptyWrapper (content: VNodeChildren) {
return this.$createElement('div', content)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Wrapper,
} from '@vue/test-utils'
import Vue from 'vue'
import { Breakpoint } from '../../../services/breakpoint'
import { preset } from '../../../presets/default'

Vue.prototype.$vuetify = {
Expand All @@ -30,6 +31,7 @@ describe('VDataIterator.ts', () => {
return mount(VDataIterator, {
mocks: {
$vuetify: {
breakpoint: new Breakpoint(preset),
lang: new Lang(preset),
theme: {
dark: false,
Expand Down
11 changes: 0 additions & 11 deletions packages/vuetify/src/components/VDataTable/VDataTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ export default VDataIterator.extend({
showGroupBy: Boolean,
// TODO: Fix
// virtualRows: Boolean,
mobileBreakpoint: {
type: Number,
default: 600,
},
height: [Number, String],
hideDefaultHeader: Boolean,
caption: String,
Expand Down Expand Up @@ -135,13 +131,6 @@ export default VDataIterator.extend({
colspan: this.headersLength || this.computedHeaders.length,
}
},
isMobile (): boolean {
// Guard against SSR render
// https://github.com/vuetifyjs/vuetify/issues/7410
if (this.$vuetify.breakpoint.width === 0) return false

return this.$vuetify.breakpoint.width < this.mobileBreakpoint
},
columnSorters (): Record<string, DataTableCompareFunction> {
return this.computedHeaders.reduce<Record<string, DataTableCompareFunction>>((acc, header) => {
if (header.sort) acc[header.value] = header.sort
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5375,19 +5375,19 @@ exports[`VDataTable.ts should render with item scoped slot 1`] = `
</thead>
<tbody>
<div>
{"item":{"name":"Frozen Yogurt","calories":159,"fat":6,"carbs":24,"protein":4,"iron":"1%"},"isSelected":false,"isExpanded":false,"headers":[{"text":"Dessert (100g serving)","align":"left","sortable":false,"value":"name"},{"text":"Calories","value":"calories"},{"text":"Fat (g)","value":"fat"},{"text":"Carbs (g)","value":"carbs"},{"text":"Protein (g)","value":"protein"},{"text":"Iron (%)","value":"iron"}],"index":0}
{"item":{"name":"Frozen Yogurt","calories":159,"fat":6,"carbs":24,"protein":4,"iron":"1%"},"isSelected":false,"isExpanded":false,"isMobile":false,"headers":[{"text":"Dessert (100g serving)","align":"left","sortable":false,"value":"name"},{"text":"Calories","value":"calories"},{"text":"Fat (g)","value":"fat"},{"text":"Carbs (g)","value":"carbs"},{"text":"Protein (g)","value":"protein"},{"text":"Iron (%)","value":"iron"}],"index":0}
</div>
<div>
{"item":{"name":"Ice cream sandwich","calories":237,"fat":9,"carbs":37,"protein":4.3,"iron":"1%"},"isSelected":false,"isExpanded":false,"headers":[{"text":"Dessert (100g serving)","align":"left","sortable":false,"value":"name"},{"text":"Calories","value":"calories"},{"text":"Fat (g)","value":"fat"},{"text":"Carbs (g)","value":"carbs"},{"text":"Protein (g)","value":"protein"},{"text":"Iron (%)","value":"iron"}],"index":1}
{"item":{"name":"Ice cream sandwich","calories":237,"fat":9,"carbs":37,"protein":4.3,"iron":"1%"},"isSelected":false,"isExpanded":false,"isMobile":false,"headers":[{"text":"Dessert (100g serving)","align":"left","sortable":false,"value":"name"},{"text":"Calories","value":"calories"},{"text":"Fat (g)","value":"fat"},{"text":"Carbs (g)","value":"carbs"},{"text":"Protein (g)","value":"protein"},{"text":"Iron (%)","value":"iron"}],"index":1}
</div>
<div>
{"item":{"name":"Eclair","calories":262,"fat":16,"carbs":23,"protein":6,"iron":"7%"},"isSelected":false,"isExpanded":false,"headers":[{"text":"Dessert (100g serving)","align":"left","sortable":false,"value":"name"},{"text":"Calories","value":"calories"},{"text":"Fat (g)","value":"fat"},{"text":"Carbs (g)","value":"carbs"},{"text":"Protein (g)","value":"protein"},{"text":"Iron (%)","value":"iron"}],"index":2}
{"item":{"name":"Eclair","calories":262,"fat":16,"carbs":23,"protein":6,"iron":"7%"},"isSelected":false,"isExpanded":false,"isMobile":false,"headers":[{"text":"Dessert (100g serving)","align":"left","sortable":false,"value":"name"},{"text":"Calories","value":"calories"},{"text":"Fat (g)","value":"fat"},{"text":"Carbs (g)","value":"carbs"},{"text":"Protein (g)","value":"protein"},{"text":"Iron (%)","value":"iron"}],"index":2}
</div>
<div>
{"item":{"name":"Cupcake","calories":305,"fat":3.7,"carbs":67,"protein":4.3,"iron":"8%"},"isSelected":false,"isExpanded":false,"headers":[{"text":"Dessert (100g serving)","align":"left","sortable":false,"value":"name"},{"text":"Calories","value":"calories"},{"text":"Fat (g)","value":"fat"},{"text":"Carbs (g)","value":"carbs"},{"text":"Protein (g)","value":"protein"},{"text":"Iron (%)","value":"iron"}],"index":3}
{"item":{"name":"Cupcake","calories":305,"fat":3.7,"carbs":67,"protein":4.3,"iron":"8%"},"isSelected":false,"isExpanded":false,"isMobile":false,"headers":[{"text":"Dessert (100g serving)","align":"left","sortable":false,"value":"name"},{"text":"Calories","value":"calories"},{"text":"Fat (g)","value":"fat"},{"text":"Carbs (g)","value":"carbs"},{"text":"Protein (g)","value":"protein"},{"text":"Iron (%)","value":"iron"}],"index":3}
</div>
<div>
{"item":{"name":"Gingerbread","calories":356,"fat":16,"carbs":49,"protein":3.9,"iron":"16%"},"isSelected":false,"isExpanded":false,"headers":[{"text":"Dessert (100g serving)","align":"left","sortable":false,"value":"name"},{"text":"Calories","value":"calories"},{"text":"Fat (g)","value":"fat"},{"text":"Carbs (g)","value":"carbs"},{"text":"Protein (g)","value":"protein"},{"text":"Iron (%)","value":"iron"}],"index":4}
{"item":{"name":"Gingerbread","calories":356,"fat":16,"carbs":49,"protein":3.9,"iron":"16%"},"isSelected":false,"isExpanded":false,"isMobile":false,"headers":[{"text":"Dessert (100g serving)","align":"left","sortable":false,"value":"name"},{"text":"Calories","value":"calories"},{"text":"Fat (g)","value":"fat"},{"text":"Carbs (g)","value":"carbs"},{"text":"Protein (g)","value":"protein"},{"text":"Iron (%)","value":"iron"}],"index":4}
</div>
</tbody>
</table>
Expand Down

0 comments on commit f4b4f0a

Please sign in to comment.