Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

Commit

Permalink
fix: Work around styles-components parent selector issue, noissue
Browse files Browse the repository at this point in the history
Adds double ampersands to work around
styled-components issue #3265:
styled-components/styled-components#3265
  • Loading branch information
diondiondion committed Nov 9, 2021
1 parent 72485ca commit 75247dc
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 28 deletions.
10 changes: 5 additions & 5 deletions src/Button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ const FocusRing = styled.span.withConfig({
transition: opacity 250ms linear;
will-change: opacity;
${Wrapper}.focus-visible > & {
${Wrapper}.focus-visible > && {
top: -${_3px};
left: -${_3px};
bottom: -${_3px};
Expand All @@ -194,7 +194,7 @@ const FocusRing = styled.span.withConfig({
transition-duration: 50ms;
}
/* prettier-ignore */
${Wrapper}:not(.is-disabled):active > & {
${Wrapper}:not(.is-disabled):active > && {
opacity: 1;
transition-duration: 50ms;
}
Expand All @@ -216,12 +216,12 @@ const HoverShade = styled.span`
box-shadow: inset 0 0 0.25rem rgba(0, 0, 0, 0.5);
}
/* prettier-ignore */
${Wrapper}:not(.is-disabled):hover > & {
${Wrapper}:not(.is-disabled):hover > && {
opacity: 1;
transition-duration: 50ms;
}
/* prettier-ignore */
${Wrapper}:not(.is-disabled):active > & {
${Wrapper}:not(.is-disabled):active > && {
opacity: 0;
transition-duration: 250ms;
}
Expand All @@ -235,7 +235,7 @@ const Content = styled.span`
`;

/**
* The button label should just have some horinzontal spacing.
* The button label should just have some horizontal spacing.
* But if `textOverflow="ellipsis" is set, the Button label
* will have overflow set to "hidden", which can cause the
* descenders of some characters (g, y, j) to be cut off.
Expand Down
6 changes: 4 additions & 2 deletions src/ButtonCore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ const Clickable = styled.button`
cursor: pointer;
}
&:focus:not(.focus-visible) {
&:focus:not(.focus-visible),
&:focus:not([data-focus-visible-added]) {
outline: none;
}
&.focus-visible {
&.focus-visible,
&[data-focus-visible-added] {
outline: 3px solid currentColor;
outline-offset: 3px;
}
Expand Down
21 changes: 13 additions & 8 deletions src/MenuList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ const Item = styled.li`
display: block;
`;

const Link = styled(ButtonCore).withConfig({
shouldForwardProp: prop =>
![...textLinkProps, 'isHighlighted'].includes(prop),
})`
const Link = styled(ButtonCore)
.attrs(({isHighlighted}) => ({
className: isHighlighted ? 'is-highlighted' : '',
}))
.withConfig({
shouldForwardProp: prop =>
![...textLinkProps, 'isHighlighted'].includes(prop),
})`
position: relative;
display: flex;
align-items: center;
Expand All @@ -57,7 +61,8 @@ const Link = styled(ButtonCore).withConfig({
outline: none;
}
&.focus-visible:focus {
${Wrapper}[data-focus-visible-added] &&.is-highlighted,
&[data-focus-visible-added]:focus {
outline: none;
&::after {
Expand Down Expand Up @@ -106,9 +111,9 @@ const IconWrapper = styled.span`
opacity: ${p => p.theme.textDimStrength};
${Link}:hover:not(.is-disabled) > &,
.is-focused:not(.is-disabled) > &,
.is-active:not(.is-disabled) > & {
${Link}:hover:not(.is-disabled) > &&,
${Link}[data-focus-visible-added]:not(.is-disabled) > &&,
.is-active:not(.is-disabled) > && {
opacity: 1;
}
`;
Expand Down
8 changes: 4 additions & 4 deletions src/Pill/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ const HoverShade = styled.span`
will-change: opacity;
/* prettier-ignore */
${Wrapper}:not(.is-disabled):hover > & {
${Wrapper}:not(.is-disabled):hover > && {
opacity: 1;
transition-duration: 50ms;
}
/* prettier-ignore */
${Wrapper}:not(.is-disabled):active > & {
${Wrapper}:not(.is-disabled):active > && {
opacity: 0;
transition-duration: 250ms;
}
Expand All @@ -160,7 +160,7 @@ const FocusRing = styled.span.withConfig({
transition: opacity 250ms linear;
will-change: opacity;
${Wrapper}.focus-visible > & {
${Wrapper}.focus-visible > && {
top: -${_3px};
left: -${_3px};
bottom: -${_3px};
Expand All @@ -173,7 +173,7 @@ const FocusRing = styled.span.withConfig({
}
/* prettier-ignore */
${Wrapper}:not(.is-disabled):active > & {
${Wrapper}:not(.is-disabled):active > && {
opacity: 1;
transition-duration: 50ms;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Table/shared/RowSelectButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ const ButtonWrapper = styled(ButtonCore)`
outline: none;
}
tr[aria-selected='true'] & {
tr[aria-selected='true'] && {
opacity: 1;
}
tr[data-highlighted] &.focus-visible {
tr[data-highlighted] &&[data-focus-visible-added] {
opacity: 1;
}
`;
Expand Down
4 changes: 2 additions & 2 deletions src/Table/shared/TableColumnHeader/ClickableHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ const StyledSortArrow = styled(ArrowIcon).withConfig({shouldForwardProp})`
opacity: 0;
`}
${ClickabilityIndicator}:hover &,
${ClickabilityIndicator}.focus-visible & {
${ClickabilityIndicator}:hover &&,
${ClickabilityIndicator}.focus-visible && {
fill: ${p => p.theme.links};
opacity: 1;
transition-delay: 0.15s;
Expand Down
10 changes: 5 additions & 5 deletions src/Table/shared/TableRowHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ const Th = withTableContext(styled.th.withConfig({
border-bottom: ${p => borderValue(p.theme)};
${headerBackgroundColor}
tr[aria-selected] & {
tr[aria-selected] && {
padding-left: ${getCheckboxColumnWidth};
}
/* Highlight SELECTABLE table rows */
tr[data-highlighted] &,
tr[data-highlighted]:focus-within & {
tr[data-highlighted] &&,
tr[data-highlighted]:focus-within && {
background-color: ${p =>
alpha(
p.theme.links,
Math.max(0.05, +p.theme.shadeStrength / 2)
)};
}
tr[aria-selected='true'] &,
tr[aria-selected='true'][data-highlighted] & {
tr[aria-selected='true'] &&,
tr[aria-selected='true'][data-highlighted] && {
background-color: ${p =>
alpha(p.theme.links, Math.max(0.15, +p.theme.shadeStrength))};
}
Expand Down

0 comments on commit 75247dc

Please sign in to comment.