Skip to content

Commit

Permalink
Remove the unwanted OuiBreadcrumbs focus rectangle
Browse files Browse the repository at this point in the history
Also:
* Correctly color the OuiBreadcrumbs when focused
* Display the last breadcrumb in a nested breadcrumb as a normal breadcrumb

Signed-off-by: Miki <[email protected]>
  • Loading branch information
AMoo-Miki committed Sep 17, 2024
1 parent 065f61a commit b0d6a96
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
44 changes: 30 additions & 14 deletions src/components/breadcrumbs/_breadcrumbs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
}
}

.ouiBreadcrumb,
.ouiBreadcrumb__collapsedLink {
&.ouiLink {
&[class*='ouiLink--']:focus {
// .ouiLink uses a rule with !important which shows an outline
animation: none !important; // sass-lint:disable-line no-important
}
}
}

.ouiBreadcrumbs:not(.ouiBreadcrumbs__inPopover) .ouiBreadcrumbWrapper--last .ouiBreadcrumb {
font-weight: $ouiFontWeightMedium;
}
Expand Down Expand Up @@ -97,37 +107,43 @@

transform: skewX(-20deg);
border-radius: $ouiSizeXS;
}

&:not(.ouiBreadcrumbWrapper--last)::before {
background-color: $ouiBreadcrumbInactiveBackground;
}

&.ouiBreadcrumbWrapper--last::before {
background-color: $ouiBreadcrumbActiveBackground;
.ouiBreadcrumbs:not(.ouiBreadcrumbs__inPopover) & {
&.ouiBreadcrumbWrapper--last {
// This targets the last breadcrumb wrapper and sets a different text color for the breadcrumb inside it.
.ouiBreadcrumb,
.ouiBreadcrumb:hover {
color: inherit !important; // sass-lint:disable-line no-important
}

&::before {
background-color: $ouiBreadcrumbActiveBackground;
}
}
}

&:has(.ouiLink--subdued:focus)::before {
background-color: $ouiBreadcrumbFocusBackground;
}

&:not(.ouiBreadcrumbWrapper--first) {
margin-bottom: $ouiSizeXS; /* 1 */
padding-left: $ouiSizeL - $ouiSizeXS + calc($ouiBreadcrumbSpacing / 2);
}

// This targets the last breadcrumb wrapper and sets a different text color for the breadcrumb inside it.
&.ouiBreadcrumbWrapper--last .ouiBreadcrumb {
// TODO: remove important: https://github.com/opensearch-project/oui/issues/376
color: inherit !important; // sass-lint:disable-line no-important

&:hover {
color: inherit !important; // sass-lint:disable-line no-important
}
}
}

.ouiBreadcrumbWall {
background-image: linear-gradient(to right, $ouiBreadcrumbInactiveBackground 0 $ouiSizeM, transparent $ouiSizeM);
border-radius: $ouiSizeXS;
overflow: hidden;
margin-bottom: $ouiSizeXS; /* 1 */

&:has(.ouiLink--subdued:focus) {
background-image: linear-gradient(to right, $ouiBreadcrumbFocusBackground 0 $ouiSizeM, transparent $ouiSizeM);
}
}

.ouiBreadcrumbWall--single {
Expand Down
1 change: 1 addition & 0 deletions src/components/breadcrumbs/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
$ouiBreadcrumbSpacing: $ouiSizeS !default;
$ouiBreadcrumbTruncateWidth: $ouiSize * 10 !default;

$ouiBreadcrumbFocusBackground: tintOrShade($ouiTextSubduedColor, $ouiFocusChangePercent, $ouiFocusChangePercent) !default;
$ouiBreadcrumbActiveBackground: tintOrShade($ouiColorPrimary, 72%, 41%) !default;
$ouiBreadcrumbInactiveBackground: tint($ouiColorLightShade, 14%) !default;
$ouiBreadcrumbCollapsedLink: shadeOrTint($ouiColorPrimaryText, 61%, 20%) !default;
Expand Down
6 changes: 4 additions & 2 deletions src/components/breadcrumbs/breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ export const OuiBreadcrumbs: FunctionComponent<OuiBreadcrumbsProps> = ({
};
}, [responsive, functionToCallOnWindowResize]);

const isInPopover = className === 'ouiBreadcrumbs__inPopover';

const breadcrumbElements = breadcrumbs.map((breadcrumb, index) => {
const {
text,
Expand Down Expand Up @@ -249,7 +251,7 @@ export const OuiBreadcrumbs: FunctionComponent<OuiBreadcrumbsProps> = ({
ref={ref}
className={breadcrumbClasses}
title={innerText}
aria-current={isLastBreadcrumb ? 'page' : 'false'}
aria-current={isLastBreadcrumb && !isInPopover ? 'page' : 'false'}
{...breadcrumbRest}>
{text}
</span>
Expand All @@ -260,7 +262,7 @@ export const OuiBreadcrumbs: FunctionComponent<OuiBreadcrumbsProps> = ({
{(ref, innerText) => (
<OuiLink
ref={ref}
color={isLastBreadcrumb ? 'text' : 'subdued'}
color={isLastBreadcrumb && !isInPopover ? 'text' : 'subdued'}
onClick={onClick}
href={href}
className={breadcrumbClasses}
Expand Down

0 comments on commit b0d6a96

Please sign in to comment.