Skip to content

Commit c578897

Browse files
authored
feat(theming)!: remove focusVisibleRef prop and polyfill scoping element (#1771)
1 parent a973164 commit c578897

File tree

30 files changed

+159
-182
lines changed

30 files changed

+159
-182
lines changed

docs/migration.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ consider additional positioning prop support on a case-by-case basis.
137137

138138
- `DrawerModal`: renamed to `Drawer`
139139
- `TooltipModal`: removed `popperModifiers` prop (see [note](#breaking-changes))
140+
- Removed internal `useFocusVisible` hook for both `Modal` and `Drawer`. For
141+
non-Garden modal content that still depends on the polyfill for focus styling,
142+
either:
143+
1. Use updated `:focus-visible` styling provided by the `focusStyles` and
144+
`getFocusBoxShadow` theming utilities, or
145+
1. Use
146+
[@zendeskgarden/container-focusvisible](https://www.npmjs.com/package/@zendeskgarden/container-focusvisible)
147+
to restore the polyfill
140148
- Removed `GARDEN_PLACEMENT` type export. Use `ITooltipModalProps['placement']` instead.
141149
- Subcomponent exports for `Modal` have been deprecated and will be removed in a future major version.
142150
Update to subcomponent properties (e.g., `Modal.Body`).
@@ -182,6 +190,9 @@ consider additional positioning prop support on a case-by-case basis.
182190
scheme to custom components that are not part of the Garden framework. It is
183191
recommended to utilize this stopgap measure until such components can be updated
184192
to leverage the full capabilities of v9 `getColor`.
193+
- The `focusVisibleRef` prop (and the resulting scoping `<div>`) has been
194+
removed from `<ThemeProvider>`. Current browser support obviates the need for a
195+
`:focus-visible` polyfill.
185196
- Utility function `getColor` has been refactored with a signature that supports
186197
v9 light/dark modes. Replace usage with `getColorV8` until custom components can
187198
be upgraded to utilize the new `getColor` function.

package-lock.json

Lines changed: 98 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/accordions/src/elements/accordion/components/Header.tsx

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
* found at http://www.apache.org/licenses/LICENSE-2.0.
66
*/
77

8-
import React, { useState, FocusEvent, forwardRef, HTMLAttributes, useMemo } from 'react';
8+
import React, { useState, forwardRef, HTMLAttributes, useMemo } from 'react';
99
import { composeEventHandlers } from '@zendeskgarden/container-utilities';
1010
import ChevronDown from '@zendeskgarden/svg-icons/src/16/chevron-down-stroke.svg';
1111
import { useAccordionContext, useSectionContext, HeaderContext } from '../../../utils';
12-
import { StyledHeader, StyledRotateIcon, COMPONENT_ID as buttonGardenId } from '../../../styled';
12+
import { StyledHeader, StyledRotateIcon } from '../../../styled';
1313

1414
const HeaderComponent = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>((props, ref) => {
15-
const { onClick, onFocus, onBlur, onMouseOver, onMouseOut, role, children, ...other } = props;
15+
const { onClick, onMouseOver, onMouseOut, role, children, ...other } = props;
1616
const {
1717
level: ariaLevel,
1818
isCompact,
@@ -22,7 +22,6 @@ const HeaderComponent = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement
2222
expandedSections
2323
} = useAccordionContext();
2424
const sectionValue = useSectionContext();
25-
const [isFocused, setIsFocused] = useState(false);
2625
const [isHovered, setIsHovered] = useState(false);
2726
const isExpanded = expandedSections.includes(sectionValue);
2827
/**
@@ -39,18 +38,6 @@ const HeaderComponent = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement
3938
type: 'button',
4039
value: sectionValue
4140
});
42-
const onHeaderFocus = (e: FocusEvent) => {
43-
e.persist();
44-
45-
setTimeout(() => {
46-
const isAccordionButton = e.target.getAttribute('data-garden-id') === buttonGardenId;
47-
const isFocusVisible = e.target.getAttribute('data-garden-focus-visible');
48-
49-
if (isAccordionButton && isFocusVisible) {
50-
setIsFocused(true);
51-
}
52-
}, 0);
53-
};
5441

5542
const value = useMemo(
5643
() => ({
@@ -65,14 +52,11 @@ const HeaderComponent = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement
6552
<StyledHeader
6653
isCollapsible={isCollapsible}
6754
isExpanded={isExpanded}
68-
isFocused={isFocused}
6955
{...(getHeaderProps({
7056
ref,
7157
'aria-level': ariaLevel,
7258
role: role === undefined || role === null ? role : 'heading',
7359
onClick: composeEventHandlers(onClick, onTriggerClick),
74-
onFocus: composeEventHandlers(onFocus, onHeaderFocus),
75-
onBlur: composeEventHandlers(onBlur, () => setIsFocused(false)),
7660
onMouseOver: composeEventHandlers(onMouseOver, () => setIsHovered(true)),
7761
onMouseOut: composeEventHandlers(onMouseOut, () => setIsHovered(false)),
7862
...other

packages/accordions/src/styled/accordion/StyledHeader.spec.tsx

Lines changed: 0 additions & 30 deletions
This file was deleted.

packages/accordions/src/styled/accordion/StyledHeader.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
import styled from 'styled-components';
99
import { retrieveComponentStyles, DEFAULT_THEME, focusStyles } from '@zendeskgarden/react-theming';
10+
import { StyledButton } from './StyledButton';
1011

1112
const COMPONENT_ID = 'accordions.header';
1213

1314
interface IStyledHeader {
14-
isFocused?: boolean;
1515
isExpanded?: boolean;
1616
isCollapsible?: boolean;
1717
}
@@ -33,8 +33,7 @@ export const StyledHeader = styled.div.attrs<IStyledHeader>({
3333
focusStyles({
3434
theme: props.theme,
3535
inset: true,
36-
condition: props.isFocused,
37-
selector: '&:focus-within'
36+
selector: `&:has(${StyledButton}:focus-visible)`
3837
})}
3938
4039
${props => retrieveComponentStyles(COMPONENT_ID, props)};

packages/buttons/src/styled/StyledButton.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,7 @@ const colorStyles = (props: IButtonProps & ThemeProps<DefaultTheme>) => {
185185
186186
/* prettier-ignore */
187187
&:hover ${StyledIcon},
188-
&:focus-visible ${StyledIcon},
189-
&[data-garden-focus-visible] ${StyledIcon} {
188+
&:focus-visible ${StyledIcon} {
190189
color: ${props.isNeutral && getColorV8('neutralHue', shade + 100, props.theme)};
191190
}
192191

packages/chrome/demo/stories/SheetStory.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ export const SheetStory: Story<IArgs> = ({
9494
}) => (
9595
<>
9696
<ThemeProvider
97-
focusVisibleRef={null}
9897
theme={
9998
((parentTheme: DefaultTheme) => ({
10099
...parentTheme,

packages/chrome/src/styled/header/StyledHeaderItem.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ export const StyledHeaderItem = styled(StyledBaseHeaderItem as 'button').attrs({
5555
inset: props.maxY
5656
})}
5757
58-
&:focus-visible:active,
59-
&[data-garden-focus-visible]:active {
58+
&:focus-visible:active {
6059
box-shadow: none;
6160
}
6261

0 commit comments

Comments
 (0)