-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PBNTR-568] Adding React Dropdown cleaning feature (#3793)
**What does this PR do?** Adding React Dropdown cleaning feature **Screenshots:** <img width="883" alt="image" src="https://github.com/user-attachments/assets/b1080c00-9299-46ac-a481-196ca05026ff"> **How to test?** 1. Go to the Dropdown kit page 2. Scroll down to the Clear Selection doc #### Checklist: - [x] **LABELS** Add a label: `enhancement`, `bug`, `improvement`, `new kit`, `deprecated`, or `breaking`. See [Changelog & Labels](https://github.com/powerhome/playbook/wiki/Changelog-&-Labels) for details. - [x] **DEPLOY** I have added the `milano` label to show I'm ready for a review. - [ ] **TESTS** I have added test coverage to my code.
- Loading branch information
1 parent
88302fb
commit 86b841a
Showing
7 changed files
with
71 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
playbook/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_clear_selection.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React, { useRef } from 'react' | ||
import { Button, Dropdown } from 'playbook-ui' | ||
|
||
const options = [ | ||
{ | ||
label: "United States", | ||
value: "United States", | ||
}, | ||
{ | ||
label: "Canada", | ||
value: "Canada", | ||
}, | ||
{ | ||
label: "Pakistan", | ||
value: "Pakistan", | ||
} | ||
] | ||
|
||
const DropdownClearSelection = (props) => { | ||
const dropdownRef = useRef(null) | ||
|
||
const handleReset = () => { | ||
if (dropdownRef.current) { | ||
dropdownRef.current.clearSelected() | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<Dropdown | ||
defaultValue={options[2]} | ||
options={options} | ||
ref={dropdownRef} | ||
{...props} | ||
/> | ||
<Button | ||
marginTop="md" | ||
onClick={handleReset} | ||
text="Reset" | ||
/> | ||
</> | ||
) | ||
} | ||
|
||
export default DropdownClearSelection |
1 change: 1 addition & 0 deletions
1
playbook/app/pb_kits/playbook/pb_dropdown/docs/_dropdown_clear_selection.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
To use an external control (like a reset button) to clear Dropdown selection, you can make use of the `useRef` hook. You must pass a ref to the Dropdown component and use that ref within the onClick for the external control in the way shown in the code snippet below. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters