Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify JS and add readme.
  • Loading branch information
afercia committed Nov 10, 2022
commit 2ac420e58d62d75a14c9e917ad7594c41baeac3c
11 changes: 6 additions & 5 deletions packages/interface/src/components/interface-skeleton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,14 @@ function InterfaceSkeleton(
<div className="interface-interface-skeleton__editor">
{ !! header && isDistractionFree && (
<NavigableRegion
initial={ isDistractionFree ? 'hidden' : 'hover' }
whileHover="hover"
variants={ headerVariants }
transition={ { type: 'tween', delay: 0.8 } }
className="interface-interface-skeleton__header"
aria-label={ mergedLabels.header }
useMotion={ true }
motionProps={ {
initial: isDistractionFree ? 'hidden' : 'hover',
whileHover: 'hover',
variants: headerVariants,
transition: { type: 'tween', delay: 0.8 },
} }
>
{ header }
</NavigableRegion>
Expand Down
38 changes: 38 additions & 0 deletions packages/interface/src/components/navigable-region/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# NavigableRegion
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this should be moved to the components package insect it's meant to be used in conjunction with useNavigateRegions from that package.


`NavigableRegion` renders an ARIA landmark region that's meant to be used together with the `useNavigateRegions` component from the `@wordpress/components` package. The ARIA landmark is a `div` element with a `role="region"` attribute and an `aria-label` attribute. It's made focusable by the means of a `tabindex="-1"` attribute so that `useNavigateRegions` can set focus on it and allow keyboard navigation through the regions in the editor.

It also renders a child `div` element that is responsible to set a negative `z-index` stack level, to make sure the focus style is always visible, regardless of other elements that may cut-off the focus style outline otherwise.

It can use a CSS animation via the `motion` component.

## Props

### children

The component that should be rendered as content.

- Type: React Element
- Required: Yes

### className

The CSS class that will be added to the classes of the wrapper div.

- Type: `String`
- Required: No

### ariaLabel

A meaningful name for the ARIA landmark region.

- Type: `String`
- Required: Yes

### motionProps

Properties of `motionProps` object will be used by the `motion` component to set a CSS animation on the wrapper div.

- Type: `Object`
- Required: No
- Default: `{}`
14 changes: 2 additions & 12 deletions packages/interface/src/components/navigable-region/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,9 @@ export default function NavigableRegion( {
children,
className,
ariaLabel,
useMotion = false,
...props
motionProps = {},
} ) {
const Tag = useMotion ? motion.div : 'div';

const motionProps = useMotion
? {
initial: props.initial,
whileHover: props.whileHover,
variants: props.variants,
transition: props.transition,
}
: {};
const Tag = Object.keys( motionProps ).length ? motion.div : 'div';

return (
<Tag
Expand Down