AgnosticUI / agnosticui

AgnosticUI is a set of UI primitives that start their lives in clean HTML and CSS. These standards compliant components are then copied to our framework implementations in: React, Vue 3, Angular, and Svelte.
https://agnosticui.com
Apache License 2.0
723 stars 47 forks source link

agnostic-svelte pagination component reactivity #236

Closed ocolefed closed 2 years ago

ocolefed commented 2 years ago

Describe the bug Depending on your point of view, this is either a bug or a feature request. It's a bug in that it's unexpected behaviour, but a feature request in that the expected behaviour can be added.

The Pagination component from agnostic-svelte does not allow you to dynamically bind the maximum number of pages in the pagination sequence. If the number of pages is changed, the component does not actually update until the next time that the current prop is changed.

To Reproduce

<script>
  let total = 10;
  let current = 1;
  const pageGenerator = usePagination({offset: 2 });
</script>

<input bind:value={total} />
<Pagination bind:total bind:current {pageGenerator} />

Expected behavior If the total prop (determining the number of pages to show) is changed by the parent component, the number of pages the pagination component displays should also change.

Resolution This issue can be resolved with a very simple change, adding total to the reactive genPages call in Pagination.svelte:133, causing the page generator to be re-triggered whenever the total number of pages changes (in addition to the current page). ( see PR #235 )

roblevintennis commented 2 years ago

Thanks for the PR -- merged 💪