Skip to content

Commit ec3e4cf

Browse files
authored
fix(pagination): mark selected option in page-sizes-select component (#10884)
### Related Ticket(s) Closes #10553 https://jsw.ibm.com/browse/ADCMS-3821 ### Description Fixes a bug where the initial value of the `page-size` attribute on the `<bx-pagination>` component previously did not set the correct `<option>` element within the `<bx-page-sizes-select>` component. ### Changelog **Changed** - Updated the `slotchange` handler for the `<bx-page-sizes-select>` component to set the `selected` attribute when applicable. ### Testing Instructions * Navigate to Pagination > Default story * Enter a different value for "Number of rows per page (page-size)", using one of the other values in the dropdown, eg. 20 or 30 * Click the "Open canvas in new tab" button, this will initiate the story with the set value for `page-size` to test the bug * Should see the value you set for the items per page drop down.
1 parent 29434ed commit ec3e4cf

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

packages/carbon-web-components/src/components/pagination/page-sizes-select.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,18 @@ class BXPageSizesSelect extends FocusMixin(LitElement) {
5454
* @param event The event.
5555
*/
5656
private _handleSlotChange({ target }: Event) {
57-
const { _selectNode: selectNode } = this;
57+
const { _selectNode: selectNode, value } = this;
5858
while (selectNode.firstChild) {
5959
selectNode.removeChild(selectNode.firstChild);
6060
}
6161
(
6262
(target as HTMLSlotElement).assignedNodes() as HTMLOptionElement[]
6363
).forEach((item) => {
64-
selectNode?.appendChild(item.cloneNode(true));
64+
const optionElement = item.cloneNode(true) as HTMLOptionElement;
65+
if (value && Number(optionElement.value) === value) {
66+
optionElement.selected = true;
67+
}
68+
selectNode?.appendChild(optionElement);
6569
});
6670
}
6771

packages/carbon-web-components/src/components/pagination/pagination-story.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license
33
*
4-
* Copyright IBM Corp. 2019, 2022
4+
* Copyright IBM Corp. 2019, 2023
55
*
66
* This source code is licensed under the Apache-2.0 license found in the
77
* LICENSE file in the root directory of this source tree.
@@ -52,7 +52,7 @@ export default {
5252
knobs: {
5353
'bx-pagination': () => ({
5454
atLastPage: boolean(
55-
'Explicitly state that the user is at the last page (at-last-apge)',
55+
'Explicitly state that the user is at the last page (at-last-page)',
5656
false
5757
),
5858
pageSize: number('Number of rows per page (page-size)', 10),

0 commit comments

Comments
 (0)