Skip to content
Prev Previous commit
Next Next commit
Restore conditional aria-label for the scrollable section.
  • Loading branch information
afercia committed Feb 9, 2023
commit 04b9c374ca4f2d09b1ffac5fa534fdc00c7d7a4c
6 changes: 5 additions & 1 deletion packages/components/src/modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,11 @@ function UnforwardedModal(
role="document"
onScroll={ onContentContainerScroll }
ref={ contentRef }
aria-label={ __( 'Scrollable section' ) }
aria-label={
hasScrollableContent
? __( 'Scrollable section' )
: undefined
}
tabIndex={ hasScrollableContent ? 0 : undefined }
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think we can extract all this logic into a hook const { ref, props } = useScrollable();

and just basically apply the "ref" and "props" to the element that is supposed to be scrollable? I think it might bring some clarity to the code here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, not sure why we need childrenContainerRef can't we just check the height of the scrollable itself (or at least its children) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The scrollable element has a fixed height,
The height of the content (the children) determines the actual content overflow, when it's greater than the scrollable height.
There may be multipole children though. Not sure how to calculate eh height of multiple children that could also be dynamically rendered. Seems to me the simplest option is to check for the height of an additional container.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think we can extract all this logic into a hook

I'm all for better abstraction and improvements. I'd prefer to do that when enhancing the Scrollable component though. See #45809

>
{ ! __experimentalHideHeader && (
Expand Down