Skip to content

Commit

Permalink
Add onOpenChange handler for contextMenu (#226)
Browse files Browse the repository at this point in the history
* Add onOpenChange handler for contextMenu

* changelog and bump version

* minor version
  • Loading branch information
miafan23 authored Sep 4, 2024
1 parent aa43bbc commit d9d81fd
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
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

0 comments on commit d9d81fd

Please sign in to comment.