Skip to content

Commit d3cb170

Browse files
committed
refactor(EuiButtonGroup): update the disabled behavior to ensure a background/fill for selected buttons
1 parent 49f9df4 commit d3cb170

4 files changed

Lines changed: 33 additions & 20 deletions

File tree

packages/eui/src/components/button/button_context.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ export const EuiButtonContext = createContext<{
3131
* Set by `EuiButtonGroup` with `variant="selection"` to resolve per-button
3232
* selected state and its derived display props.
3333
*/
34-
getSelectionProps?: (id: string) => {
34+
getSelectionProps?: (
35+
id: string,
36+
isDisabled?: boolean
37+
) => {
3538
isSelected: boolean;
3639
fill: boolean;
3740
display?: 'fill' | 'base';

packages/eui/src/components/button/button_group/button_group.styles.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,10 @@ export const euiButtonGroupButtonsStyles = (euiThemeContext: UseEuiTheme) => {
263263
264264
${segmentedChildrenStyles}
265265
266-
*:where(.euiButton, .euiButtonIcon):is(${euiDisabledSelector}) {
267-
background-color: transparent;
266+
*:where(.euiButton, .euiButtonIcon) {
267+
&:where(:is(${euiDisabledSelector}):not([aria-pressed='true'])) {
268+
background-color: transparent;
269+
}
268270
}
269271
270272
&:where([data-dividers='true'] &) {
@@ -316,20 +318,22 @@ export const euiButtonGroupButtonsStyles = (euiThemeContext: UseEuiTheme) => {
316318
317319
&:where([data-variant='selection'][data-display='regular'] &) {
318320
*:where(.euiButton, .euiButtonIcon):is([aria-pressed='true']) {
319-
background-color: ${euiTheme.colors.backgroundLightText};
321+
&:not(:is(${euiDisabledSelector})) {
322+
background-color: ${euiTheme.colors.backgroundLightText};
320323
321-
${highContrastModeStyles(euiThemeContext, {
322-
none: `
323-
background-color: ${euiTheme.colors.backgroundLightText};
324-
`,
325-
preferred: `
326-
border: ${euiTheme.border.thin};
327-
`,
328-
forced: `
329-
background-color: ${euiTheme.colors.fullShade};
330-
border: none;
331-
`,
332-
})}
324+
${highContrastModeStyles(euiThemeContext, {
325+
none: `
326+
background-color: ${euiTheme.colors.backgroundLightText};
327+
`,
328+
preferred: `
329+
border: ${euiTheme.border.thin};
330+
`,
331+
forced: `
332+
background-color: ${euiTheme.colors.fullShade};
333+
border: none;
334+
`,
335+
})}
336+
}
333337
}
334338
}
335339
@@ -343,6 +347,10 @@ export const euiButtonGroupButtonsStyles = (euiThemeContext: UseEuiTheme) => {
343347
`,
344348
})}
345349
}
350+
351+
*:where(.euiButton, .euiButtonIcon):is(${euiDisabledSelector}) {
352+
background-color: transparent;
353+
}
346354
}
347355
`,
348356
noWrap: css`
@@ -454,7 +462,7 @@ const _highContrastStyles = (euiThemeContext: UseEuiTheme) => {
454462
color: ${euiTheme.colors.emptyShade};
455463
background-color: ${euiTheme.colors.fullShade};
456464
457-
&:is(:hover, :focus):not(${euiDisabledSelector}) {
465+
&:is(:hover, :focus):not(:is(${euiDisabledSelector})) {
458466
&::before {
459467
border-color: ${euiTheme.colors.textInverse};
460468
}

packages/eui/src/components/button/button_group/button_group.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,10 +468,12 @@ export const EuiButtonGroupChildren: FunctionComponent<ChildrenModeProps> = ({
468468
fill: false,
469469
}),
470470
...(isSelection && {
471-
getSelectionProps: (id: string) => {
471+
getSelectionProps: (id: string, _isDisabled?: boolean) => {
472472
const selected = isSelected(id);
473473
const isInverse = display === 'inverse';
474-
const hasFill = selected && display === 'highlighted';
474+
const hasFill =
475+
(selected && display === 'highlighted') ||
476+
!!(selected && _isDisabled);
475477

476478
return {
477479
isSelected: selected,

packages/eui/src/components/button/use_button_common_props.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export function useEuiButtonCommonProps<
8989
});
9090

9191
const selectionProps =
92-
id != null ? groupContext.getSelectionProps?.(id) : undefined;
92+
id != null ? groupContext.getSelectionProps?.(id, isDisabled) : undefined;
9393

9494
const onClick = selectionProps
9595
? (event: React.MouseEvent<HTMLElement>) => {

0 commit comments

Comments
 (0)