-
-
Notifications
You must be signed in to change notification settings - Fork 261
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
Dispatch change
event from Pagination
and Select
#1497
Conversation
Thanks for taking the time to work on this. A couple of things:
|
@metonym thanks for following up. I think I can address both your points with an example: Given a page with two pagination toolbars set up with on-demand data loading <script>
import 'carbon-components-svelte/css/white.css'
import {
DataTable,
Pagination
} from 'carbon-components-svelte'
import { goto } from '$app/navigation'
import { page } from '$app/stores'
export let data
$: tablePage = $page.url.searchParams.get('page')
? parseInt($page.url.searchParams.get('page'), pageSize)
: 1
let pageSize = 25
/**
* changePage via pagination dropdown or prev/next buttons
* @param e
*/
const changePage = async e => {
const url = new URL($page.url)
url.searchParams.set('page', e.detail.page)
await goto(`?${url.searchParams.toString()}`)
}
</script>
<DataTable
title="Pizzas around the world"
headers={data.headers}
rows={data.rows}
>
<!-- top pagination -->
<Pagination
page={tablePage}
{pageSize}
totalItems={data.itemCount}
pageSizeInputDisabled
on:change={changePage}
/>
</DataTable>
<!-- bottom pagination -->
<Pagination
page={tablePage}
{pageSize}
totalItems={data.itemCount}
pageSizeInputDisabled
on:change={changePage}
/> Notice my It was necessary for me to update the logic for Carbon's |
I'll take another look at this. I'd like to couple this with #1518 |
@metonym sounds good, let me know if you need any modifications. |
I'm still not understanding the need to rename the dispatched event in |
This PR enhances This is tricky for me to put into words succinctly, so here's a demo that hopefully achieves that 😃: https://stackblitz.com/edit/vitejs-vite-vsxhbs?file=src%2FApp.svelte Since The use case is to pass in the |
I was a bit off base in my earlier comment. The main reason I am dispatching The current |
i'm hitting this too. I have a pagination element on the top and bottom of a datatable. and because this is because the we need something that only triggers for user input -- which @theetrain is suggesting to dispatch a |
bump. the workaround for this is really hacky. this PR is needed to align with the behavior of the https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/change_event |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm on board with this.
Three things:
change
also needs to be forwarded to the non-inlineselect
- moving forward, let's have dispatched event names not conflict with native names. How about changing the dispatched name from "input" to "update"?
- docs for
Select
need to be updated
Updated, now This decision relates to my recent change to Dropdown in #1569. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Side note, it would be nice if the note I added to the @event JSDoc appeared on the rendered docs. Perhaps I can open a separate issue for that.
Non-blocking: event descriptions should now be supported by the recent sveld
upgrade. If you rebase on master
and re-run yarn; yarn build:docs
, the Pagination
event description for "change" should appear in generated docs metadata and types.
Dispatch `input` instead of `change` when props change internally since `change` is a user event and `input` is an internal event
Whenever the user interacts with Pagination, `change` is dispatched
Adjust Select docs to use native change event handling.
Brought in part by sveld 0.18
Released in v0.71.0 |
Closes #1491
Pagination
change
event from<Pagination>
whenever user interacts with "previous" button, "next" button, page dropdown, or page size dropdownSelect
change
event from<Select>
; necessary for Pagination to react to changesinput
instead ofchange
Side note, it would be nice if the note I added to the
@event
JSDoc appeared on the rendered docs. Perhaps I can open a separate issue for that.