Skip to content

The open alternative to Salesforce, designed for AI.

Gate twenty-ui interaction handlers on the element being clickable (#24311)

Raphaël Bosi5bb09a10b235
diff --git a/packages/twenty-ui/src/data-display/AvatarOrIcon/AvatarOrIcon.tsx b/packages/twenty-ui/src/data-display/AvatarOrIcon/AvatarOrIcon.tsx
index 9311072b3c8..617722e5633 100644
--- a/packages/twenty-ui/src/data-display/AvatarOrIcon/AvatarOrIcon.tsx
+++ b/packages/twenty-ui/src/data-display/AvatarOrIcon/AvatarOrIcon.tsx
@@ -48,59 +48,53 @@ export const AvatarOrIcon = ({
);
}
- const isClickable = isDefined(onClick);
const accessibleLabel = isNonEmptyString(placeholder)
? placeholder
: 'Avatar';
- if (isIconInverted || isDefined(IconBackgroundColor)) {
+ const iconContent =
+ isIconInverted || isDefined(IconBackgroundColor) ? (
+ <div
+ className={styles.iconWithBackgroundContainer}
+ style={
+ isDefined(IconBackgroundColor)
+ ? ({
+ '--avatar-or-icon-background': IconBackgroundColor,
+ } as React.CSSProperties)
+ : undefined
+ }
+ >
+ <Icon
+ color={theme.font.color.inverted}
+ size={theme.icon.size.sm}
+ stroke={theme.icon.stroke.sm}
+ aria-hidden
+ />
+ </div>
+ ) : (
+ <Icon
+ size={theme.icon.size.sm}
+ stroke={theme.icon.stroke.sm}
+ color={IconColor || 'currentColor'}
+ aria-hidden
+ />
+ );
+
+ if (isDefined(onClick)) {
return (
<div
className={styles.wrapper}
- data-clickable={isClickable || undefined}
- role={isClickable ? 'button' : undefined}
- tabIndex={isClickable ? 0 : undefined}
- aria-label={isClickable ? accessibleLabel : undefined}
+ data-clickable={true}
+ role="button"
+ tabIndex={0}
+ aria-label={accessibleLabel}
onClick={onClick}
onKeyDown={handleClickableElementKeyDown}
>
- <div
- className={styles.iconWithBackgroundContainer}
- style={
- isDefined(IconBackgroundColor)
- ? ({
- '--avatar-or-icon-background': IconBackgroundColor,
- } as React.CSSProperties)
- : undefined
- }
- >
- <Icon
- color={theme.font.color.inverted}
- size={theme.icon.size.sm}
- stroke={theme.icon.stroke.sm}
- aria-hidden
- />
- </div>
+ {iconContent}
</div>
);
}
- return (
- <div
- className={styles.wrapper}
- data-clickable={isClickable || undefined}
- role={isClickable ? 'button' : undefined}
- tabIndex={isClickable ? 0 : undefined}
- aria-label={isClickable ? accessibleLabel : undefined}
- onClick={onClick}
- onKeyDown={handleClickableElementKeyDown}
- >
- <Icon
- size={theme.icon.size.sm}
- stroke={theme.icon.stroke.sm}
- color={IconColor || 'currentColor'}
- aria-hidden
- />
- </div>
- );
+ return <div className={styles.wrapper}>{iconContent}</div>;
};
diff --git a/packages/twenty-ui/src/input/ColorSchemeCard/ColorSchemeCard.tsx b/packages/twenty-ui/src/input/ColorSchemeCard/ColorSchemeCard.tsx
index 200da2f124d..ed7d9683fa8 100644
--- a/packages/twenty-ui/src/input/ColorSchemeCard/ColorSchemeCard.tsx
+++ b/packages/twenty-ui/src/input/ColorSchemeCard/ColorSchemeCard.tsx
@@ -26,27 +26,42 @@ const ColorSchemeSegment = ({
}: ColorSchemeSegmentProps) => {
const grayScale = variant === 'Dark' ? GRAY_SCALE_DARK : GRAY_SCALE_LIGHT;
+ const segmentClassName = clsx(styles.colorSchemeBackground, className);
+ const segmentStyle = {
+ '--color-scheme-card-background': grayScale.gray4,
+ '--color-scheme-card-border-color': grayScale.gray5,
+ '--color-scheme-card-content-background': grayScale.gray1,
+ '--color-scheme-card-content-color': grayScale.gray12,
+ ...style,
+ } as React.CSSProperties;
+ const segmentContent = <div className={styles.colorSchemeContent}>Aa</div>;
+
+ if (isDefined(onClick)) {
+ return (
+ <div
+ className={segmentClassName}
+ style={segmentStyle}
+ role="button"
+ tabIndex={0}
+ aria-label={variant}
+ onClick={onClick}
+ onKeyDown={handleClickableElementKeyDown}
+ onMouseEnter={onMouseEnter}
+ onMouseLeave={onMouseLeave}
+ >
+ {segmentContent}
+ </div>
+ );
+ }
+
return (
<div
- className={clsx(styles.colorSchemeBackground, className)}
- style={
- {
- '--color-scheme-card-background': grayScale.gray4,
- '--color-scheme-card-border-color': grayScale.gray5,
- '--color-scheme-card-content-background': grayScale.gray1,
- '--color-scheme-card-content-color': grayScale.gray12,
- ...style,
- } as React.CSSProperties
- }
- role={isDefined(onClick) ? 'button' : undefined}
- tabIndex={isDefined(onClick) ? 0 : undefined}
- aria-label={isDefined(onClick) ? variant : undefined}
- onClick={onClick}
- onKeyDown={handleClickableElementKeyDown}
+ className={segmentClassName}
+ style={segmentStyle}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
>
- <div className={styles.colorSchemeContent}>Aa</div>
+ {segmentContent}
</div>
);
};
@@ -62,26 +77,36 @@ export const ColorSchemeCard = ({
onClick,
className,
}: ColorSchemeCardProps) => {
+ const mixedSegments = (
+ <>
+ <ColorSchemeSegment
+ style={{ borderTopRightRadius: 0, borderBottomRightRadius: 0 }}
+ variant="Light"
+ />
+ <ColorSchemeSegment
+ style={{ borderTopLeftRadius: 0, borderBottomLeftRadius: 0 }}
+ variant="Dark"
+ />
+ </>
+ );
+
if (variant === 'System') {
return (
<div className={clsx(styles.container, className)}>
- <div
- className={styles.mixedColorSchemeSegment}
- role={isDefined(onClick) ? 'button' : undefined}
- tabIndex={isDefined(onClick) ? 0 : undefined}
- aria-label={isDefined(onClick) ? variant : undefined}
- onClick={onClick}
- onKeyDown={handleClickableElementKeyDown}
- >
- <ColorSchemeSegment
- style={{ borderTopRightRadius: 0, borderBottomRightRadius: 0 }}
- variant="Light"
- />
- <ColorSchemeSegment
- style={{ borderTopLeftRadius: 0, borderBottomLeftRadius: 0 }}
- variant="Dark"
- />
- </div>
+ {isDefined(onClick) ? (
+ <div
+ className={styles.mixedColorSchemeSegment}
+ role="button"
+ tabIndex={0}
+ aria-label={variant}
+ onClick={onClick}
+ onKeyDown={handleClickableElementKeyDown}
+ >
+ {mixedSegments}
+ </div>
+ ) : (
+ <div className={styles.mixedColorSchemeSegment}>{mixedSegments}</div>
+ )}
<div
className={styles.checkmarkContainer}
data-selected={selected || undefined}
diff --git a/packages/twenty-ui/src/json-visualizer/components/internal/JsonNodeValue.tsx b/packages/twenty-ui/src/json-visualizer/components/internal/JsonNodeValue.tsx
index 3e92d6484a9..6da8577611c 100644
--- a/packages/twenty-ui/src/json-visualizer/components/internal/JsonNodeValue.tsx
+++ b/packages/twenty-ui/src/json-visualizer/components/internal/JsonNodeValue.tsx
@@ -21,19 +21,25 @@ export const JsonNodeValue = ({
onNodeValueClick?.(valueAsString);
};
- return (
- <span
- className={clsx(
- styles.text,
- highlighting === 'blue' && styles.blue,
- highlighting === 'red' && styles.red,
- )}
- role={isInteractive ? 'button' : undefined}
- tabIndex={isInteractive ? 0 : undefined}
- onClick={isInteractive ? handleClick : undefined}
- onKeyDown={handleClickableElementKeyDown}
- >
- {valueAsString}
- </span>
+ const valueClassName = clsx(
+ styles.text,
+ highlighting === 'blue' && styles.blue,
+ highlighting === 'red' && styles.red,
);
+
+ if (isInteractive) {
+ return (
+ <span
+ className={valueClassName}
+ role="button"
+ tabIndex={0}
+ onClick={handleClick}
+ onKeyDown={handleClickableElementKeyDown}
+ >
+ {valueAsString}
+ </span>
+ );
+ }
+
+ return <span className={valueClassName}>{valueAsString}</span>;
};