Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into UXPLATFORM-10398
Browse files Browse the repository at this point in the history
  • Loading branch information
adavijit authored May 9, 2024
2 parents 359f536 + 7fbc549 commit 4c7f1bc
Show file tree
Hide file tree
Showing 29 changed files with 42 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/terra-framework-docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Enabled `close` button in examples.
* Modified Button in `PopupStandard` example.
* Removed `ariaLabel` from `PopupStandard` example.
* Updated `terra-slide-panel` example to use `terra-buttons`.

## 1.86.0 - (May 8, 2024)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import classNames from 'classnames/bind';
import SlidePanel from 'terra-slide-panel';
import Button from 'terra-button';
import styles from './SlidePanelDocCommon.test.module.scss';

const cx = classNames.bind(styles);
Expand Down Expand Up @@ -29,15 +30,15 @@ class SlidePanelDemo extends React.Component {
id="test-slide"
mainContent={(
<div className={cx('main-content')}>
<button type="button" id="other-button-1" className={cx('button')} onClick={SlidePanelDemo.handleOtherButton}>Other Button 1</button>
<button type="button" id="test-toggle" className={cx('button')} onClick={this.handlePanelToggle}>toggle</button>
<button type="button" id="another-button" className={cx('button')} onClick={SlidePanelDemo.handleOtherButton}>Another Button</button>
<Button text="Other Button 1" id="other-button-1" onClick={SlidePanelDemo.handleOtherButton} />
<Button text="Toggle" id="test-toggle" onClick={this.handlePanelToggle} />
<Button text="Another Button" id="another-button" onClick={SlidePanelDemo.handleOtherButton} />
</div>
)}
panelContent={(
<div id="panel-content" className={cx('panel-content')}>
<button type="button" id="other-button-2" className={cx('button')} onClick={SlidePanelDemo.handleOtherButton}>Other Button 2</button>
<button id="focus-button" type="button" className={cx('button')} onClick={this.handlePanelToggle}>Close panel</button>
<Button text="Other Button 2" id="other-button-2" onClick={SlidePanelDemo.handleOtherButton} />
<Button text="Close panel" id="focus-button" onClick={this.handlePanelToggle} />
</div>
)}
panelAriaLabel="Panel content area"
Expand Down
3 changes: 3 additions & 0 deletions packages/terra-slide-panel/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Changed
* Updated to find the closest focusable element when disclosing.

## 3.49.0 - (April 4, 2024)

* Changed
Expand Down
33 changes: 32 additions & 1 deletion packages/terra-slide-panel/src/SlidePanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,36 @@ const defaultProps = {
panelSize: 'small',
};

/**
* Checks whether or not the given node should be focusable.
* If not focusable, find the closest parent element that is.
* If it cannot find a focusable element, return undefined.
*/
const findFocusableElement = (node) => {
const focusableElementSelector = 'a[href]:not([tabindex=\'-1\']), area[href]:not([tabindex=\'-1\']), input:not([disabled]):not([tabindex=\'-1\']), '
+ 'select:not([disabled]):not([tabindex=\'-1\']), textarea:not([disabled]):not([tabindex=\'-1\']), button:not([disabled]):not([tabindex=\'-1\']), '
+ 'iframe:not([tabindex=\'-1\']), [tabindex]:not([tabindex=\'-1\']), [contentEditable=true]:not([tabindex=\'-1\'])';

const focusableElements = [...document.body.querySelectorAll(`${focusableElementSelector}`)].filter(
element => !element.hasAttribute('disabled')
&& !element.getAttribute('aria-hidden')
&& !!(element.offsetWidth || element.offsetHeight || element.getClientRects().length)
&& window.getComputedStyle(element).visibility !== 'hidden'
&& element.closest('[inert]') === null,
);

let currentNode = node;
while (currentNode.parentElement) {
if (focusableElements.includes(currentNode)) {
return currentNode;
}

currentNode = currentNode.parentElement;
}

return undefined;
};

class SlidePanel extends React.Component {
constructor(props) {
super(props);
Expand All @@ -97,7 +127,8 @@ class SlidePanel extends React.Component {
componentDidUpdate(prevProps) {
if (this.props.isOpen && this.props.isOpen !== prevProps.isOpen) {
// Save the disclosing node for returning focus when panel is closed
this.setDisclosingNode(document.activeElement);
const disclosingNode = findFocusableElement(document.activeElement);
this.setDisclosingNode(disclosingNode);
this.panelNode.focus();
return;
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4c7f1bc

Please sign in to comment.