8000 fix(BPagination): Correctly position ellipses when hideGotoEndButtons=true. by dwgray · Pull Request #2148 · bootstrap-vue-next/bootstrap-vue-next · GitHub
[go: up one dir, main page]

Skip to content

fix(BPagination): Correctly position ellipses when hideGotoEndButtons=true. #2148

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

Merged
merged 2 commits into from
Aug 26, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ watch(pagination, (oldValue, newValue) => {

const buttons = computed(() => {
// The idea here is to create an array of all the buttons on the page control.
// This was we can keep the invariants in one place and the template code just
// This way we can keep the invariants in one place and the template code just
// iterates over the array.

const pages = numberOfPages.value
Expand All @@ -354,10 +354,11 @@ const buttons = computed(() => {
const lastPage = props.lastNumber ? 1 : 0
const hideEllipsis = props.hideEllipsis || limit <= ELLIPSIS_THRESHOLD
const hideEndButtons = props.hideGotoEndButtons ? 1 : 0
const showEndButtons = props.hideGotoEndButtons ? 0 : 1

// The first case is when all of the page buttons fit on the control, this is
// the simplest case and the only one that will create an array smaller than
// Limit + 4 - hideEndButtons *2 (the [first, last,] prev, next buttons)
// Limit + 4 - hideEndButtons * 2 (the [first, last,] prev, next buttons)

if (pages < limit + firstPage + lastPage) {
return [
Expand Down Expand Up @@ -394,7 +395,7 @@ const buttons = computed(() => {
buttons[buttons.length - 1] = NEXT_BUTTON
}

// The next case is where the buttons page buttons start at the begginning, with
// The next case is where the page buttons start at the begginning, with
// no ellipsis at the beginning, but one at the end

const halfLimit = Math.floor(limit / 2)
Expand All @@ -404,7 +405,7 @@ const buttons = computed(() => {
}

if (!hideEllipsis) {
buttons[buttons.length - 3] = ELLIPSIS_BUTTON
buttons[buttons.length - (2 + showEndButtons)] = ELLIPSIS_BUTTON
}
}

Expand All @@ -418,7 +419,7 @@ const buttons = computed(() => {
}

if (!hideEllipsis) {
buttons[2] = ELLIPSIS_BUTTON
buttons[1 + showEndButtons] = ELLIPSIS_BUTTON
}
}

Expand All @@ -431,14 +432,15 @@ const buttons = computed(() => {
}

if (!hideEllipsis) {
buttons[2] = ELLIPSIS_BUTTON
buttons[buttons.length - 3] = ELLIPSIS_BUTTON
buttons[1 + showEndButtons] = ELLIPSIS_BUTTON
buttons[buttons.length - (2 + showEndButtons)] = ELLIPSIS_BUTTON
}
}

// Enable sanity check for debugging purposes
// for (let i = 0; i < buttons.length; i++) {
// if (!buttons[i]) {
// // eslint-disable-next-line no-console
// console.log(
// `Failed: button == ${i}, limit=${limit}, pages=${pages}, firstPage=${firstPage}, lastPage=${lastPage}, value=${value}`
// )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,24 @@ describe('pagination', () => {
expect(wrapper.find('[aria-label="Go to last page"]').exists()).toBeFalsy()
})

it('has end ellipses in correct place when hideGotoEndButtons="true"', () => {
const wrapper = mount(BPagination, {
props: {totalRows: 100, perPage: 1, modelValue: 5, hideGotoEndButtons: true},
})
const buttons = wrapper.findAll('li')
const ellipses = buttons[buttons.length - 2]
expect(ellipses.attributes('role')).toBe('separator')
})

it('has start ellipses in correct place when hideGotoEndButtons="true"', () => {
const wrapper = mount(BPagination, {
props: {totalRows: 100, perPage: 1, modelValue: 5, hideGotoEndButtons: true},
})
const buttons = wrapper.findAll('li')
const [, ellipses] = buttons
expect(ellipses.attributes('role')).toBe('separator')
})

it('does not have first button when firstNumber="true"', () => {
const wrapper = mount(BPagination, {
props: {totalRows: 100, perPage: 1, modelValue: 5, firstNumber: true},
Expand Down
Loading
0