Skip to content

Commit

Permalink
CSS fixes/className cleanups
Browse files Browse the repository at this point in the history
- add styles for underlining text, but not the badge

- fix cursor on badge

- add `className` hooks to both text & badge nodes in case consumers want to customize their CSS

- misc/consistency - rename props (rest, classes, etc) to match other EUI components
  • Loading branch information
cee-chen committed Nov 21, 2023
1 parent 472161e commit 184f1b7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const renderCustomToolbar: EuiDataGridToolbarProps['renderCustomToolbar'] = ({
const mobileStyles =
!hasRoomForGridControls &&
css`
.euiDataGrid__controlBtn .euiButtonEmpty__text {
.euiDataGridToolbarControl__text {
${euiScreenReaderOnly()}
}
`;
Expand Down
30 changes: 22 additions & 8 deletions src/components/datagrid/controls/data_grid_toolbar_control.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import React, { FunctionComponent } from 'react';
import classNames from 'classnames';
import { css } from '@emotion/react';

import { EuiButtonEmpty, EuiButtonEmptyProps } from '../../button';
import { EuiNotificationBadge } from '../../badge';
Expand All @@ -19,29 +20,38 @@ export type EuiDataGridToolbarControlProps = EuiButtonEmptyProps & {

export const EuiDataGridToolbarControl: FunctionComponent<
EuiDataGridToolbarControlProps
> = ({ children, badgeContent, textProps, ...buttonProps }) => {
> = ({ children, className, badgeContent, textProps, ...rest }) => {
const classes = classNames('euiDataGridToolbarControl', className);

const badgeAriaLabel = useEuiI18n(
'euiDataGridToolbarControl.badgeAriaLabel',
'Active: {count}',
{ count: badgeContent }
);

const controlBtnClasses = classNames(
'euiDataGrid__controlBtn',
buttonProps.className
);

return (
<EuiButtonEmpty
className={classes}
size="xs"
color="text"
textProps={false}
{...buttonProps}
className={controlBtnClasses}
// Underline actual text, but not the badge
css={css`
&:focus,
&:hover:not(:disabled) {
text-decoration: none;
.euiDataGridToolbarControl__text {
text-decoration: underline;
}
}
`}
{...rest}
>
<span
{...textProps}
className={classNames(
'euiDataGridToolbarControl__text',
'eui-textTruncate',
textProps && textProps.className
)}
Expand All @@ -51,6 +61,10 @@ export const EuiDataGridToolbarControl: FunctionComponent<

{Boolean(badgeContent) && (
<EuiNotificationBadge
className="euiDataGridToolbarControl__badge"
css={css`
cursor: inherit;
`}
color="subdued"
aria-label={badgeAriaLabel}
role="marquee" // https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/marquee_role
Expand Down

0 comments on commit 184f1b7

Please sign in to comment.