Skip to content
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

Add pagination support to Select component #1316

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added

- Support for lazy loading select options with pagination.

## [9.128.1] - 2020-08-28

### Fixed
Expand Down
46 changes: 46 additions & 0 deletions react/components/EXPERIMENTAL_Select/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,49 @@ class SelectWithModalExample extends React.Component {

;<SelectWithModalExample />
```

Paginated

```js
const options = []
for (let i = 0; i < 1000; ++i) {
options.push({
value: i + 1,
label: `Option ${i + 1}`,
})
}

const sleep = ms =>
new Promise(resolve => {
setTimeout(() => {
resolve()
}, ms)
})

;<div>
<div className="mb5">
<Select
label="Paginated select"
paginated
loadOptions={async (searchTerm, prevOptions, additionalData) => {
await sleep(1000)

const filteredOptions = options.filter(({ label }) =>
label.toLowerCase().includes(searchTerm.toLowerCase())
)

return {
options: filteredOptions.slice(
prevOptions.length,
prevOptions.length + 10
),
hasMore: filteredOptions.length > prevOptions.length + 10,
}
}}
onChange={values => {
console.log(`[Select] Selected: ${JSON.stringify(values, null, 2)}`)
}}
/>
</div>
</div>
```
Loading