Skip to content

Commit bfb2708

Browse files
authored
Merge pull request #413 from eccenca/feature/noDragSwitch
Add nodrag class to Switch component by default
2 parents 07597b6 + 31073be commit bfb2708

9 files changed

Lines changed: 58 additions & 11 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- `<Switch />`
12+
- `noDrag` parameter: Add the `nodrag` class to the Switch element. Default: `true`
13+
14+
### Deprecated
15+
16+
- `preventReactFlowActionsClasses`: use `ClassNames.ReactFlow.preventAllActions`
17+
918
## [26.1.0] - 2026-08-20
1019

1120
### Added

‎src/cmem/react-flow/ReactFlow/ReactFlow.tsx‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,3 @@ const ReactFlowExtendedPlain = <T extends ReactFlowExtendedProps>(
207207
export const ReactFlowExtended = React.forwardRef(ReactFlowExtendedPlain) as <T extends ReactFlowExtendedProps>(
208208
p: T & { ref?: Ref<HTMLDivElement> },
209209
) => ReactElement;
210-
211-
/** Classes that when set for an element, prevent that they trigger react-flow dragging, wheel and panning actions. */
212-
export const preventReactFlowActionsClasses = "nodrag nopan nowheel";
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
Classes that when set for an element, prevent that they trigger react-flow dragging, wheel and panning actions.
3+
4+
This module must stay free of imports, so that basic components can use these class names without pulling the
5+
react-flow packages into their dependency chain.
6+
*/
7+
export const preventReactFlowDragClass = "nodrag";
8+
export const preventReactFlowPanClass = "nopan";
9+
export const preventReactFlowWheelClass = "nowheel";
10+
export const preventReactFlowActionsClasses = `${preventReactFlowDragClass} ${preventReactFlowPanClass} ${preventReactFlowWheelClass}`;
11+
12+
export const helperClasses = {
13+
preventDrag: preventReactFlowDragClass,
14+
preventPan: preventReactFlowPanClass,
15+
preventWheel: preventReactFlowWheelClass,
16+
preventAllActions: preventReactFlowActionsClasses,
17+
};

‎src/components/AutocompleteField/AutoCompleteField.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
} from "@blueprintjs/core";
66
import { Suggest as BlueprintSuggest } from "@blueprintjs/select";
77

8+
import { preventReactFlowDragClass } from "../../cmem/react-flow/ReactFlow/constants";
89
import { CLASSPREFIX as eccgui } from "../../configuration/constants";
910
import {
1011
ContextOverlayProps,
@@ -485,7 +486,7 @@ export function SuggestField<T, UPDATE_VALUE>(props: SuggestFieldProps<T, UPDATE
485486
query={query}
486487
// This leads to odd compile errors without "as any"
487488
popoverProps={updatedContextOverlayProps as any}
488-
popoverContentProps={{ className: "nodrag" }}
489+
popoverContentProps={{ className: preventReactFlowDragClass }}
489490
selectedItem={selectedItem}
490491
fill={fill}
491492
{...createNewItemProps}

‎src/components/Dialog/Modal.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
Overlay2Props as BlueprintOverlayProps,
66
} from "@blueprintjs/core";
77

8-
import { preventReactFlowActionsClasses } from "../../cmem";
8+
import { preventReactFlowActionsClasses } from "../../cmem/react-flow/ReactFlow/constants";
99
import { utils } from "../../common";
1010
import { CLASSPREFIX as eccgui } from "../../configuration/constants";
1111
import { TestableComponent } from "../interfaces";

‎src/components/Switch/Stories/Switch.stories.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,14 @@ WithStateLabel.args = {
2323
innerLabel: "Off",
2424
innerLabelChecked: "On",
2525
};
26+
27+
/**
28+
* By default the `nodrag` class is set, so the switch cannot be used to drag a surrounding element,
29+
* e.g. a React Flow node. Set `noDrag` to `false` to remove the class and allow the drag interaction.
30+
*/
31+
export const WithoutNoDragClass = Template.bind({});
32+
WithoutNoDragClass.args = {
33+
...Default.args,
34+
label: "Switch label, drag interaction not prevented",
35+
noDrag: false,
36+
};

‎src/components/Switch/Switch.tsx‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
SwitchProps as BlueprintSwitchProps,
66
} from "@blueprintjs/core";
77

8+
import { preventReactFlowDragClass } from "../../cmem/react-flow/ReactFlow/constants";
89
import { CLASSPREFIX as eccgui } from "../../configuration/constants";
910
import { Label } from "../Label/Label";
1011

@@ -17,18 +18,23 @@ export interface SwitchProps extends Omit<BlueprintSwitchProps, "onChange"> {
1718
* class names
1819
*/
1920
className?: string;
21+
22+
/** Adds the 'nodrag' class to the element, preventing dragging via the Switch element. Default: true */
23+
noDrag?: boolean;
2024
}
2125

22-
export const Switch = ({ onChange, className, label, ...otherProps }: SwitchProps) => {
26+
export const Switch = ({ onChange, className, label, noDrag = true, ...otherProps }: SwitchProps) => {
2327
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
2428
if (onChange) {
2529
onChange(!!e.target?.checked);
2630
}
2731
};
2832

33+
const noDragClass = noDrag ? `${preventReactFlowDragClass} ` : "";
34+
2935
return (
3036
<BlueprintSwitch
31-
className={`${eccgui}-switch ${className ?? ""} ${
37+
className={`${eccgui}-switch ${noDragClass}${className ?? ""} ${
3238
label && !otherProps.labelElement ? BlueprintClasses.INLINE : ""
3339
}`}
3440
labelElement={

‎src/extensions/react-flow/nodes/NodeContent.tsx‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ import { useStore as getStoreStateFlowV12 } from "@xyflow/react";
44
import Color from "color";
55
import { NumberSize, Resizable, ResizableProps, ResizeCallback } from "re-resizable";
66

7+
import { preventReactFlowDragClass } from "../../../cmem/react-flow/ReactFlow/constants";
78
import { intentClassName, IntentTypes } from "../../../common/Intent";
89
import { Depiction, DepictionProps } from "../../../components";
910
import { ValidIconName } from "../../../components/Icon/canonicalIconNames";
1011
import Icon from "../../../components/Icon/Icon";
1112
import OverflowText from "../../../components/Typography/OverflowText";
1213
import { CLASSPREFIX as eccgui } from "../../../configuration/constants";
14+
import { HandleDefault, HandleDefaultProps } from "../handles/HandleDefault";
1315
import { ReacFlowVersionSupportProps, ReactFlowVersions, useReactFlowVersion } from "../versionsupport";
1416

15-
import { HandleDefault, HandleDefaultProps } from "../handles/HandleDefault";
1617
import { NodeContentExtensionProps } from "./NodeContentExtension";
1718
import { NodeDefaultProps } from "./NodeDefault";
1819
import { NodeHighlightColor } from "./sharedTypes";
@@ -649,7 +650,7 @@ export function NodeContent<CONTENT_PROPS = React.HTMLAttributes<HTMLElement>>({
649650
)}
650651
</div>
651652
{(menuButtons || (showExecutionButtons && executionButtons)) && (
652-
<div className={`${eccgui}-graphviz__node__header-menu nodrag`}>
653+
<div className={`${eccgui}-graphviz__node__header-menu ${preventReactFlowDragClass}`}>
653654
{showExecutionButtons && typeof executionButtons === "function"
654655
? executionButtons(adjustedContentProps, setAdjustedContentProps)
655656
: null}
@@ -782,7 +783,7 @@ export function NodeContent<CONTENT_PROPS = React.HTMLAttributes<HTMLElement>>({
782783
(resizeDirections!.right ? ` ${eccgui}-graphviz__node__resizer--right` : "") +
783784
(resizeDirections!.bottom ? ` ${eccgui}-graphviz__node__resizer--bottom` : "")
784785
}
785-
handleWrapperClass={`${eccgui}-graphviz__node__resizer--cursorhandles` + " nodrag"}
786+
handleWrapperClass={`${eccgui}-graphviz__node__resizer--cursorhandles ${preventReactFlowDragClass}`}
786787
size={resizableSize}
787788
maxHeight={resizeMaxDimensions?.height ?? undefined}
788789
maxWidth={resizeMaxDimensions?.width ?? undefined}

‎src/index.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Classes as BlueprintClasses } from "@blueprintjs/core";
22

3+
import {helperClasses as reactFlowHelperClasses } from "./cmem/react-flow/ReactFlow/constants";
34
import { ClassNames as IntentClassNames } from "./common/Intent";
45
import * as Skeleton from "./components/Skeleton/classnames";
56
import * as TypographyClassNames from "./components/Typography/classnames";
@@ -9,12 +10,16 @@ const ClassNames = {
910
Intent: IntentClassNames,
1011
Skeleton,
1112
Typography: TypographyClassNames,
13+
ReactFlow: reactFlowHelperClasses,
1214
};
1315

16+
/** @deprecated (v27) use `ClassNames.ReactFlow.preventAllActions` */
17+
const preventReactFlowActionsClasses = reactFlowHelperClasses.preventAllActions;
18+
1419
export * from "./configuration/constants";
1520
export * from "./common";
1621
export * from "./components";
1722
export * from "./extensions";
1823
export * from "./cmem";
1924

20-
export { ClassNames };
25+
export { ClassNames, preventReactFlowActionsClasses };

0 commit comments

Comments
 (0)