Skip to content

Commit

Permalink
Merge pull request #5841 from matuzalemsteles/LPD-31019
Browse files Browse the repository at this point in the history
fix(@clayui/modal): move focus to h1
  • Loading branch information
matuzalemsteles authored Jul 12, 2024
2 parents 38afae6 + c563744 commit 557280f
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 3 deletions.
8 changes: 7 additions & 1 deletion packages/clay-css/src/scss/cadmin/components/_modals.scss
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,13 @@
// Modal Title

.modal-title {
@include clay-map-to-css(map-get($cadmin-modal, modal-title));
$_modal-title: setter(map-get($cadmin-modal, modal-title), ());

@include clay-map-to-css($_modal-title);

&[tabindex='-1'] {
@include clay-css(map-get($_modal-title, '[tabindex="-1"]'));
}

@include clay-scale-component {
font-size: $cadmin-modal-title-font-size-mobile;
Expand Down
3 changes: 3 additions & 0 deletions packages/clay-css/src/scss/cadmin/variables/_modals.scss
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ $cadmin-modal: map-deep-merge(
text-align: $cadmin-modal-title-text-align,
text-overflow: ellipsis,
white-space: nowrap,
'[tabindex="-1"]': (
outline: 0,
),
),
modal-title-indicator: (
display: inline-block,
Expand Down
8 changes: 7 additions & 1 deletion packages/clay-css/src/scss/components/_modals.scss
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,13 @@
// Modal Title

.modal-title {
@include clay-css(map-get($modal, modal-title));
$_modal-title: setter(map-get($modal, modal-title), ());

@include clay-css($_modal-title);

&[tabindex='-1'] {
@include clay-css(map-get($_modal-title, '[tabindex="-1"]'));
}

@include clay-scale-component {
font-size: $modal-title-font-size-mobile;
Expand Down
3 changes: 3 additions & 0 deletions packages/clay-css/src/scss/variables/_modals.scss
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ $modal: map-deep-merge(
text-align: $modal-title-text-align,
text-overflow: ellipsis,
white-space: nowrap,
'[tabindex="-1"]': (
outline: 0,
),
),
modal-title-indicator: (
display: inline-block,
Expand Down
1 change: 1 addition & 0 deletions packages/clay-modal/src/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const Title = ({
return (
<h1
className={classNames('modal-title', className)}
tabIndex={-1}
{...otherProps}
id={ariaLabelledby}
>
Expand Down
9 changes: 8 additions & 1 deletion packages/clay-modal/src/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,14 @@ const ClayModal = ({

useEffect(() => {
if (modalBodyElementRef.current && show && content) {
modalBodyElementRef.current.focus();
const focusedElement =
modalBodyElementRef.current.querySelector('h1');

if (focusedElement) {
focusedElement.focus();
} else {
modalBodyElementRef.current.focus();
}
}
}, [show, content]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ exports[`ModalProvider -> IncrementalInteractions renders a modal when dispatchi
<h1
class="modal-title"
id="clay-modal-label-9"
tabindex="-1"
>
Title
</h1>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ exports[`ClayModal renders 1`] = `
<h1
class="modal-title"
id="clay-modal-label-1"
tabindex="-1"
>
Foo
</h1>
Expand Down Expand Up @@ -123,6 +124,7 @@ exports[`ClayModal renders Header w/ low-level API 1`] = `
<h1
class="modal-title"
id="clay-modal-label-3"
tabindex="-1"
>
Modal Title
</h1>
Expand Down Expand Up @@ -293,6 +295,7 @@ exports[`ClayModal renders with Header 1`] = `
<h1
class="modal-title"
id="clay-modal-label-2"
tabindex="-1"
>
Foo
</h1>
Expand Down

0 comments on commit 557280f

Please sign in to comment.