Skip to content

Commit

Permalink
Remove inPopover CSS/nesting
Browse files Browse the repository at this point in the history
- in favor of JS logic instead
  • Loading branch information
cee-chen committed Jul 21, 2022
1 parent 8aa914e commit e50a5f9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 38 deletions.
10 changes: 0 additions & 10 deletions src/components/breadcrumbs/__snapshots__/breadcrumbs.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ exports[`EuiBreadcrumbs props max doesn't break when max exceeds the number of b
class="euiBreadcrumb emotion-euiBreadcrumb"
>
<span
aria-current="false"
class="euiBreadcrumb__content emotion-euiBreadcrumb__content-isTruncated"
>
Tetrapods
Expand All @@ -240,7 +239,6 @@ exports[`EuiBreadcrumbs props max doesn't break when max exceeds the number of b
class="euiBreadcrumb emotion-euiBreadcrumb"
>
<button
aria-current="false"
class="euiLink euiBreadcrumb__content emotion-euiLink-subdued-euiBreadcrumb__content-isTruncated"
type="button"
>
Expand All @@ -251,7 +249,6 @@ exports[`EuiBreadcrumbs props max doesn't break when max exceeds the number of b
class="euiBreadcrumb emotion-euiBreadcrumb"
>
<a
aria-current="false"
class="euiLink euiBreadcrumb__content emotion-euiLink-subdued-euiBreadcrumb__content-isTruncated"
href="#"
rel="noreferrer"
Expand Down Expand Up @@ -370,7 +367,6 @@ exports[`EuiBreadcrumbs props max renders all items with null 1`] = `
class="euiBreadcrumb emotion-euiBreadcrumb"
>
<span
aria-current="false"
class="euiBreadcrumb__content emotion-euiBreadcrumb__content-isTruncated"
>
Tetrapods
Expand All @@ -380,7 +376,6 @@ exports[`EuiBreadcrumbs props max renders all items with null 1`] = `
class="euiBreadcrumb emotion-euiBreadcrumb"
>
<button
aria-current="false"
class="euiLink euiBreadcrumb__content emotion-euiLink-subdued-euiBreadcrumb__content-isTruncated"
type="button"
>
Expand All @@ -391,7 +386,6 @@ exports[`EuiBreadcrumbs props max renders all items with null 1`] = `
class="euiBreadcrumb emotion-euiBreadcrumb"
>
<a
aria-current="false"
class="euiLink euiBreadcrumb__content emotion-euiLink-subdued-euiBreadcrumb__content-isTruncated"
href="#"
rel="noreferrer"
Expand Down Expand Up @@ -470,7 +464,6 @@ exports[`EuiBreadcrumbs props responsive is rendered 1`] = `
class="euiBreadcrumb emotion-euiBreadcrumb"
>
<button
aria-current="false"
class="euiLink euiBreadcrumb__content emotion-euiLink-subdued-euiBreadcrumb__content-isTruncated"
type="button"
>
Expand Down Expand Up @@ -559,7 +552,6 @@ exports[`EuiBreadcrumbs props responsive is rendered as false 1`] = `
class="euiBreadcrumb emotion-euiBreadcrumb"
>
<button
aria-current="false"
class="euiLink euiBreadcrumb__content emotion-euiLink-subdued-euiBreadcrumb__content-isTruncated"
type="button"
>
Expand Down Expand Up @@ -693,7 +685,6 @@ exports[`EuiBreadcrumbs props truncate as false is rendered 1`] = `
class="euiBreadcrumb emotion-euiBreadcrumb"
>
<button
aria-current="false"
class="euiLink euiBreadcrumb__content emotion-euiLink-subdued-euiBreadcrumb__content"
type="button"
>
Expand All @@ -704,7 +695,6 @@ exports[`EuiBreadcrumbs props truncate as false is rendered 1`] = `
class="euiBreadcrumb emotion-euiBreadcrumb"
>
<a
aria-current="false"
class="euiLink euiBreadcrumb__content emotion-euiLink-subdued-euiBreadcrumb__content-isTruncated"
href="#"
rel="noreferrer"
Expand Down
7 changes: 5 additions & 2 deletions src/components/breadcrumbs/breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ interface _EuiBreadcrumbProps {
isLastBreadcrumb?: boolean;
isOnlyBreadcrumb?: boolean;
isHeaderBreadcrumb?: boolean;
isNestedBreadcrumb?: boolean;
}

export const EuiBreadcrumb: FunctionComponent<
Expand Down Expand Up @@ -95,6 +96,7 @@ export const EuiBreadcrumbContent: FunctionComponent<
isLastBreadcrumb,
isOnlyBreadcrumb,
isHeaderBreadcrumb,
isNestedBreadcrumb,
...rest
}) => {
const classes = classNames('euiBreadcrumb__content', className);
Expand All @@ -116,7 +118,8 @@ export const EuiBreadcrumbContent: FunctionComponent<
}
}

const ariaCurrent = isLastBreadcrumb ? 'page' : undefined;
const ariaCurrent =
isLastBreadcrumb && !isNestedBreadcrumb ? 'page' : undefined;

return (
<EuiInnerText>
Expand All @@ -141,7 +144,7 @@ export const EuiBreadcrumbContent: FunctionComponent<
aria-current={ariaCurrent}
className={classes}
css={cssStyles}
color={isLastBreadcrumb ? 'text' : 'subdued'}
color={!isNestedBreadcrumb && isLastBreadcrumb ? 'text' : 'subdued'}
onClick={onClick}
href={href}
rel={rel}
Expand Down
10 changes: 0 additions & 10 deletions src/components/breadcrumbs/breadcrumbs.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,3 @@ export const euiBreadcrumbsListStyles = (euiThemeContext: UseEuiTheme) => {
`,
};
};

export const euiBreadcrumbsInPopoverStyles = ({ euiTheme }: UseEuiTheme) => ({
// Styles cast to breadcrumbs in EUI Popover
euiBreadcrumbs__inPopover: css`
& li:last-of-type > a,
& li:last-of-type > span {
color: ${euiTheme.colors.subduedText};
}
`,
});
27 changes: 11 additions & 16 deletions src/components/breadcrumbs/breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ import {
EuiBreadcrumbProps,
} from './breadcrumb';

import {
euiBreadcrumbsListStyles,
euiBreadcrumbsInPopoverStyles,
} from './breadcrumbs.styles';
import { euiBreadcrumbsListStyles } from './breadcrumbs.styles';

export type EuiBreadcrumbResponsiveMaxCount = {
/**
Expand Down Expand Up @@ -73,6 +70,13 @@ export type EuiBreadcrumbsProps = CommonProps & {
* Determines regular or EuiHeader breadcrumb styling
*/
isHeaderBreadcrumb?: boolean;

/**
* Whether this is a (contextually) nested set of breadcrumbs
* (e.g. the collapsed/overflow breadcrumbs popover).
* Determines if the last breadcrumb should be highlighted as the 'current' page.
*/
isNested?: boolean;
};

const responsiveDefault: EuiBreadcrumbResponsiveMaxCount = {
Expand All @@ -88,6 +92,7 @@ export const EuiBreadcrumbs: FunctionComponent<EuiBreadcrumbsProps> = ({
truncate = true,
max = 5,
isHeaderBreadcrumb = false,
isNested = false,
...rest
}) => {
const ariaLabel = useEuiI18n('euiBreadcrumbs.nav.ariaLabel', 'Breadcrumbs');
Expand Down Expand Up @@ -122,12 +127,6 @@ export const EuiBreadcrumbs: FunctionComponent<EuiBreadcrumbsProps> = ({
truncate && breadcrumbsListStyles.isTruncated,
];

// Breadcrumb link styles in EuiPopover
const breadcrumbsInPopoverStyles = euiBreadcrumbsInPopoverStyles(euiTheme);
const cssBreadcrumbsInPopoverStyles = [
breadcrumbsInPopoverStyles.euiBreadcrumbs__inPopover,
];

const limitBreadcrumbs = (
breadcrumbs: ReactNode[],
max: number,
Expand All @@ -142,11 +141,6 @@ export const EuiBreadcrumbs: FunctionComponent<EuiBreadcrumbsProps> = ({
start + breadcrumbs.length - limit
);

if (overflowBreadcrumbs.length) {
overflowBreadcrumbs[overflowBreadcrumbs.length - 1]['aria-current'] =
'false';
}

for (let i = 0; i < limit; i++) {
// We'll alternate with displaying breadcrumbs at the end and at the start, but be biased
// towards breadcrumbs the end so that if max is an odd number, we'll have one more
Expand Down Expand Up @@ -176,7 +170,7 @@ export const EuiBreadcrumbs: FunctionComponent<EuiBreadcrumbsProps> = ({
isFirstBreadcrumb={breadcrumbsAtStart.length === 0}
>
<EuiBreadcrumbs
css={cssBreadcrumbsInPopoverStyles}
isNested
breadcrumbs={overflowBreadcrumbs}
responsive={false}
truncate={false}
Expand All @@ -197,6 +191,7 @@ export const EuiBreadcrumbs: FunctionComponent<EuiBreadcrumbsProps> = ({
isFirstBreadcrumb={index === 0}
isLastBreadcrumb={index === breadcrumbs.length - 1}
isOnlyBreadcrumb={breadcrumbs.length === 1}
isNestedBreadcrumb={isNested}
{...breadcrumb}
/>
</EuiBreadcrumb>
Expand Down

0 comments on commit e50a5f9

Please sign in to comment.