Skip to content

Commit

Permalink
feat(pagination+pagination-nav): disabled styling now works in BS V4.…
Browse files Browse the repository at this point in the history
…beta.2 (#1381)

* feat(pagination): disabled styling now works in BS V4.beta.2

Removing custom style for disabled links as it is now working in native bootstrap  V4.beta.2 CSS

* pagination: remove no longer needed CSS
  • Loading branch information
tmorehouse committed Nov 20, 2017
1 parent 19ba693 commit d51349f
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 136 deletions.
155 changes: 76 additions & 79 deletions src/components/pagination-nav/pagination-nav.vue
Expand Up @@ -2,101 +2,98 @@
.b-pagination .page-item { .b-pagination .page-item {
user-select: none; user-select: none;
} }
.b-pagination .page-item.disabled { /* Bootstrap V4.beta.2 (and beta.1) missing focus styling for active link */
cursor: not-allowed;
opacity: .65;
}
.b-pagination .page-item .page-link.active:focus { .b-pagination .page-item .page-link.active:focus {
box-shadow: 0 0 0 3px rgba(0,123,255,.5); box-shadow: 0 0 0 3px rgba(0,123,255,.5);
z-index: 1; z-index: 1;
} }
</style> </style>


<script> <script>
import { assign } from '../../utils/object'; import { assign } from '../../utils/object'
import { KeyCodes } from '../../utils'; import { KeyCodes } from '../../utils'
import { paginationMixin } from '../../mixins'; import { paginationMixin } from '../../mixins'
import { pickLinkProps } from '../link/link'; import { pickLinkProps } from '../link/link'
// Props needed for router links // Props needed for router links
const routerProps = pickLinkProps('activeClass','exactActiveClass','append','exact','replace','target','rel'); const routerProps = pickLinkProps('activeClass','exactActiveClass','append','exact','replace','target','rel')
// Props object // Props object
const props = assign( const props = assign(
// pagination-nav specific props // pagination-nav specific props
{ {
numberOfPages: { numberOfPages: {
type: Number, type: Number,
default: 1 default: 1
}, },
baseUrl: { baseUrl: {
type: String, type: String,
default: '/' default: '/'
}, },
useRouter: { useRouter: {
type: Boolean, type: Boolean,
default: false default: false
}, },
linkGen: { linkGen: {
type: Function, type: Function,
default: null default: null
},
pageGen: {
type: Function,
default: null
}
}, },
// Router specific props pageGen: {
routerProps type: Function,
); default: null
}
},
// Router specific props
routerProps
)
// Our render function is brought in via the pagination mixin // Our render function is brought in via the pagination mixin
export default { export default {
mixins: [ paginationMixin ], mixins: [ paginationMixin ],
props, props,
computed: { computed: {
// Used by render function to trigger wraping in '<nav>' element // Used by render function to trigger wraping in '<nav>' element
isNav() { isNav() {
return true; return true
} }
},
methods: {
onClick(pageNum, evt) {
this.currentPage = pageNum
},
makePage(pagenum) {
if (this.pageGen && typeof this.pageGen === 'function') {
return this.pageGen(pagenum)
}
return pagenum
},
makeLink(pagenum) {
if (this.linkGen && typeof this.linkGen === 'function') {
return this.linkGen(pagenum)
}
const link = `${this.baseUrl}${pagenum}`
return this.useRouter ? { path: link } : link
}, },
methods: { linkProps(pagenum) {
onClick(pageNum, evt) { const link = this.makeLink(pagenum)
this.currentPage = pageNum; let props = {
}, href: typeof link === 'string' ? link : void 0,
makePage(pagenum) { target: this.target || null,
if (this.pageGen && typeof this.pageGen === 'function') { rel: this.rel || null,
return this.pageGen(pagenum); disabled: this.disabled
} }
return pagenum; if (this.useRouter || typeof link === 'object') {
}, props = assign(props, {
makeLink(pagenum) { to: link,
if (this.linkGen && typeof this.linkGen === 'function') { exact: this.exact,
return this.linkGen(pagenum); activeClass: this.activeClass,
} exactActiveClass: this.exactActiveClass,
const link = `${this.baseUrl}${pagenum}`; append: this.append,
return this.useRouter ? { path: link } : link; replace: this.replace
}, })
linkProps(pagenum) { }
const link = this.makeLink(pagenum); return props
let props = {
href: typeof link === 'string' ? link : void 0,
target: this.target || null,
rel: this.rel || null,
disabled: this.disabled
};
if (this.useRouter || typeof link === 'object') {
props = assign(props, {
to: link,
exact: this.exact,
activeClass: this.activeClass,
exactActiveClass: this.exactActiveClass,
append: this.append,
replace: this.replace
});
}
return props;
}
} }
}; }
}
</script> </script>
108 changes: 51 additions & 57 deletions src/components/pagination/pagination.vue
@@ -1,77 +1,71 @@
<style> <style>
.b-pagination .page-item { .b-pagination .page-item {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none; user-select: none;
} }
.b-pagination .page-item.disabled { /* Bootstrap V4.beta.2 (and beta.1) missing focus styling for active link */
cursor: not-allowed;
opacity: .65;
}
.b-pagination .page-item .page-link.active:focus { .b-pagination .page-item .page-link.active:focus {
box-shadow: 0 0 0 3px rgba(0,123,255,.5); box-shadow: 0 0 0 3px rgba(0,123,255,.5);
z-index: 1; z-index: 1;
} }
</style> </style>


<script> <script>
import { paginationMixin } from '../../mixins'; import { paginationMixin } from '../../mixins'
import { isVisible } from '../../utils/dom'; import { isVisible } from '../../utils/dom'
import { KeyCodes } from '../../utils'; import { KeyCodes } from '../../utils'
const props = { const props = {
perPage: { perPage: {
type: Number, type: Number,
default: 20 default: 20
}, },
totalRows: { totalRows: {
type: Number, type: Number,
default: 20 default: 20
}, },
ariaControls: { ariaControls: {
type: String, type: String,
default: null default: null
} }
}; }
// Our render function is brought in from the pagination mixin // Our render function is brought in from the pagination mixin
export default { export default {
mixins: [ paginationMixin ], mixins: [ paginationMixin ],
props, props,
computed: { computed: {
numberOfPages() { numberOfPages() {
const result = Math.ceil(this.totalRows / this.perPage); const result = Math.ceil(this.totalRows / this.perPage)
return (result < 1) ? 1 : result; return (result < 1) ? 1 : result
}
},
methods: {
// These methods are used by the render function
onClick(num, evt) {
// Handle edge cases where number of pages has changed (i.e. if perPage changes)
if (num > this.numberOfPages) {
num = this.numberOfPages
} else if (num < 1) {
num = 1
}
this.currentPage = num;
this.$nextTick(() => {
// Keep the current button focused if possible
const target = evt.target
if (isVisible(target) && this.$el.contains(target) && target.focus) {
target.focus()
} else {
this.focusCurrent()
} }
})
this.$emit('change', this.currentPage)
}, },
methods: { makePage(pagenum) {
// These methods are used by the render function return pagenum
onClick(num, evt) { },
// Handle edge cases where number of pages has changed (i.e. if perPage changes) linkProps(pagenum) {
if (num > this.numberOfPages) { return { href: '#' }
num = this.numberOfPages;
} else if (num < 1) {
num = 1;
}
this.currentPage = num;
this.$nextTick(() => {
// Keep the current button focused if possible
const target = evt.target;
if (isVisible(target) && this.$el.contains(target) && target.focus) {
target.focus();
} else {
this.focusCurrent();
}
});
this.$emit('change', this.currentPage);
},
makePage(pagenum) {
return pagenum;
},
linkProps(pagenum) {
return { href: '#' };
}
} }
}; }
}
</script> </script>

0 comments on commit d51349f

Please sign in to comment.