Skip to content
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

- `utils`
- `useComputedStyleFallback` option for `CssCustomProperties`: if the CSSOM does not provide any property name for the used selector, e.g. because the declarations are part of a constructed and adopted stylesheet, then the names are read from the computed style of the matching element; disabled by default because the computed style also contains all inherited custom properties
- `<Switch />`
- `noDrag` parameter: Add the `nodrag` class to the Switch element. Default: `true`

### Changed

Expand Down
11 changes: 11 additions & 0 deletions src/components/Switch/Stories/Switch.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,14 @@ WithStateLabel.args = {
innerLabel: "Off",
innerLabelChecked: "On",
};

/**
* By default the `nodrag` class is set, so the switch cannot be used to drag a surrounding element,
* e.g. a React Flow node. Set `noDrag` to `false` to remove the class and allow the drag interaction.
*/
export const WithoutNoDragClass = Template.bind({});
WithoutNoDragClass.args = {
...Default.args,
label: "Switch label, drag interaction not prevented",
noDrag: false,
};
9 changes: 7 additions & 2 deletions src/components/Switch/Switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,23 @@ export interface SwitchProps extends Omit<BlueprintSwitchProps, "onChange"> {
* class names
*/
className?: string;

/** Adds the 'nodrag' class to the element, preventing dragging via the Switch element. Default: true */
noDrag?: boolean;
}

export const Switch = ({ onChange, className, label, ...otherProps }: SwitchProps) => {
export const Switch = ({ onChange, className, label, noDrag = true, ...otherProps }: SwitchProps) => {
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
if (onChange) {
onChange(!!e.target?.checked);
}
};

const noDragClass = noDrag ? "nodrag " : "";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why explicitly only nodrag and not also nopan nowheel? THos 3 classes could be imported via preventReactFlowActionsClasses from ReactFlow.tsx, this could also add more context about this change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The user interacts via click with the switch, not with the pan or wheel controls. Leaving out nopan and nowheel seem to be reasonable to me, it would be unexpected if the zoom in/out is not working when the pointer is over the switch.


return (
<BlueprintSwitch
className={`${eccgui}-switch ${className ?? ""} ${
className={`${eccgui}-switch ${noDragClass}${className ?? ""} ${
label && !otherProps.labelElement ? BlueprintClasses.INLINE : ""
}`}
labelElement={
Expand Down
Loading