Skip to content

Commit

Permalink
Added document for event bubbling and capturing for the Dropdown co…
Browse files Browse the repository at this point in the history
…mponent. (#1892)

* #1811 - add document for event bubbling and capturing

* Update event bubbling example

* #1811 - Update the example code
  • Loading branch information
AkhilXavier95 authored Oct 19, 2023
1 parent 9c50eb9 commit 1c50e0e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
35 changes: 35 additions & 0 deletions stories/Components/Dropdown.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { Settings, Delete, Search } from "neetoicons";

import { Button, Dropdown, Tag, Input, Typography } from "components";

import { EVENT_BUBBLING_CAPTURING } from "./constants";

import { icons } from "../constants";

import DropdownStoriesDocs from "!raw-loader!./DropdownStoriesDocs.mdx";
Expand Down Expand Up @@ -353,6 +355,38 @@ const CustomDropdown = args => {

CustomDropdown.storyName = "Custom Dropdown";

const EventBubblingAndCapturing = args => {
const { Menu, MenuItem } = Dropdown;

return (
<div
className="neeto-ui-rounded neeto-ui-shadow-md h-40 w-1/2 cursor-pointer border-2 border-solid p-5"
onClick={() => alert("Clicked on the card")}
>
<div className="w-10" onClick={event => event.stopPropagation()}>
<Dropdown label="Dropdown" {...args}>
<Menu>
<MenuItem.Button isActive>Active</MenuItem.Button>
<MenuItem.Button>Disabled</MenuItem.Button>
<MenuItem.Button style="danger">Delete</MenuItem.Button>
</Menu>
</Dropdown>
</div>
</div>
);
};

EventBubblingAndCapturing.storyName = "Event bubbling and capturing";
EventBubblingAndCapturing.parameters = {
docs: {
source: { code: EVENT_BUBBLING_CAPTURING },
description: {
story:
"To stop event bubbling in the `Dropdown` component, you can wrap the `Dropdown` component inside a `div` or another suitable container and add an `onClick` handler to stop the event propagation.",
},
},
};

export {
Default,
TriggerStyles,
Expand All @@ -364,6 +398,7 @@ export {
ControlledDropdown,
CustomTarget,
CustomDropdown,
EventBubblingAndCapturing,
};

export default metadata;
22 changes: 22 additions & 0 deletions stories/Components/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,25 @@ export const PALETTE_PICKER_CODE = `const OnlyPalettePicker = () => {
</div>
);
};`;

export const EVENT_BUBBLING_CAPTURING = `const EventBubblingAndCapturing = () => {
const { Menu, MenuItem, Divider } = Dropdown;
const listItems = ["Action", "Another action", "Something else here"];
return (
<div
className="neeto-ui-rounded neeto-ui-shadow-md h-40 w-1/2 cursor-pointer border-2 border-solid p-5"
onClick={() => alert("Clicked on the card")}
>
<div className="w-10" onClick={event => event.stopPropagation()}>
<Dropdown label="Dropdown" {...args}>
<Menu>
<MenuItem.Button isActive>Active</MenuItem.Button>
<MenuItem.Button>Disabled</MenuItem.Button>
<MenuItem.Button style="danger">Delete</MenuItem.Button>
</Menu>
</Dropdown>
</div>
</div>
);
};`;

0 comments on commit 1c50e0e

Please sign in to comment.