Skip to content

Commit

Permalink
STCOM-1238v2 - reduce 'focus()' calls within SelectList/Selection (#2249
Browse files Browse the repository at this point in the history
)

* reduce 'focus()' calls within SelectList/Selection

* comment selection adjustment

* remove unnecessary assignment

* log changes
  • Loading branch information
JohnC-80 authored Mar 13, 2024
1 parent c256140 commit 360d54b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* Fix `<FilterAccordionHeader>` does not have correct `aria-label` when `label` prop type is string. Fixes STCOM-1271.
* Add `number-generator` icon. Refs STCOM-1269.
* Accordions retain their z-index after being blurred, and assume the highest z-index when focus enters them. Refs STCOM-1238.
* `<Selection>` should only move focus back to its control/trigger if focus within the list. Refs STCOM-1238.

## [12.0.5](https://github.com/folio-org/stripes-components/tree/v12.0.4) (2024-02-28)
[Full Changelog](https://github.com/folio-org/stripes-components/compare/v12.0.4...v12.0.5)
Expand Down
15 changes: 11 additions & 4 deletions lib/Accordion/Accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,20 @@ const Accordion = (props) => {
const handleFocusIn = () => {
if (!focused) {
updateFocused(true);
const highest = getHighestStackOrder();
if (zIndex !== highest) {
updateZIndex(highest);
}
updateZIndex((cur) => {
if(content.current.matches(':focus-within')) {
// we assign one greater than the highest z-index value.
const highest = getHighestStackOrder() + 1;
if (cur !== highest) {
return highest;
}
}
return cur;
});
}
}


const handleFocusOut = () => {
updateFocused(false);
}
Expand Down
5 changes: 4 additions & 1 deletion lib/Selection/SelectList.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ class SelectList extends React.Component {
// like a good overlay, send focus back to our trigger when we close...
if (prevProps.visible && !this.props.visible) {
if (this.props.controlRef.current) {
this.props.controlRef.current.focus();
// we only need to send focus back to the control if focus is still within the list.
if(this.container.current.matches(':focus-within')) {
this.props.controlRef.current.focus();
}
}
}

Expand Down

0 comments on commit 360d54b

Please sign in to comment.