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

feat(Popover): Add onChange callback #88

Merged
merged 2 commits into from Feb 19, 2021

Conversation

cogwirrel
Copy link
Member

Issue #, if available:

Description of changes:

Adds an onChange callback for users so we can know when the popover was opened and closed, eg to fetch data to display in the popover.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

/**
* Optional callback called when the popover is opened or closed
*/
onChange?: (visible: boolean) => void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rename it to onClose and onOpen to be more explicit? MaterialUI Popover already has a onClose property that we could use to trigger the onClose

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about it being more in line with the ExpandableSection where there's an onChange which is passed true or false, but I guess that only makes sense if the user can control the components' state too. Will see if I can also add a visible prop so you can then do something like:

const [visible, setVisible] = useState(false);

<Popover visible={visible} onChange={setVisible}> ... </Popover>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow that was a learning experience! Having a visible: boolean parameter doesn't work nicely on the first render - ie visible = true still doesn't show the popover since the ref is not set until after our first render... Doesn't seem to be a neat way to get that working, so I think best not to expose a visible prop :)

Have renamed to onClose and onOpen :)

@mteichtahl
Copy link
Contributor

mteichtahl commented Feb 19, 2021 via email

@cogwirrel cogwirrel merged commit 16cfc0e into main Feb 19, 2021
@cogwirrel cogwirrel deleted the feature/popover_onchange_callback branch February 19, 2021 05:27
aws-prototyping-bot added a commit that referenced this pull request Feb 19, 2021
## [1.0.33](v1.0.32...v1.0.33) (2021-02-19)

### Features

* **Popover:** Add onOpen and onClosed callbacks ([#88](#88)) ([16cfc0e](16cfc0e))
@aws-prototyping-bot
Copy link
Collaborator

🎉 This PR is included in version 1.0.33 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants