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 onOpenChange handler for contextMenu #226

Merged
merged 3 commits into from
Sep 4, 2024
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Changelog

## 2.11.0
- [feature] support onOpenChange handler for contextMenu

## 2.10.2
- [feature] upgrade @mapbox/mbx-assembly to 1.6.0

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mapbox/mr-ui",
"version": "2.10.2",
"version": "2.11.0",
"description": "UI components for Mapbox projects",
"main": "index.js",
"homepage": "./",
Expand Down
6 changes: 5 additions & 1 deletion src/components/context-menu/context-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Option = {
interface Props {
children: ReactNode;
onChange: (value: string) => void;
onOpenChange?: (open: boolean) => void;
options: Array<Options>;
themeControlWrapper?: string;
themeItem?: string;
Expand All @@ -30,6 +31,7 @@ interface Props {
export default function ContextMenu({
children,
onChange,
onOpenChange,
options,
themeControlWrapper = 'bg-white round shadow-darken10 px6 py6 txt-s wmin240',
themeItem = 'px6 py6 round color-blue-on-hover bg-darken5-on-hover',
Expand Down Expand Up @@ -93,7 +95,7 @@ export default function ContextMenu({
}

return (
<ContextMenuPrimitive.Root>
<ContextMenuPrimitive.Root onOpenChange={onOpenChange}>
<ContextMenuPrimitive.Trigger asChild>
{children}
</ContextMenuPrimitive.Trigger>
Expand Down Expand Up @@ -143,6 +145,8 @@ ContextMenu.propTypes = {
* - The value. A string matching the `value` field of one of the `options`
*/
onChange: PropTypes.func.isRequired,
/** Event handler called when the open state of the context menu changes. */
onOpenChange: PropTypes.func,
/** Assembly classes to apply to the menu container */
themeControlWrapper: PropTypes.string,
/** Assembly classes to apply to menu items */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default function Example() {
return (
<ContextMenu
onChange={(value => console.log('value is: ', value))}
onOpenChange={open => console.log('context menu open state', open)}
options={[
{
options: [
Expand Down