From 57925778cd659ed8e7bccdb06f11d83447e74a40 Mon Sep 17 00:00:00 2001 From: John Coburn Date: Mon, 30 Sep 2024 08:47:40 -0500 Subject: [PATCH] STCOM-1343 refactor away from `findDOMNode` (#2352) * provide refs where able * remove wrapping elements from RowMeasurer and CellMeasurer * metasection header * fix useImperativeHandle in meta-accordion * resolve MCL tests, point at srh branch with fix... * have accordion supply its own container for header/hotkey catching. * switch from branch of stripes-react-hotkeys * update yarn.lock to use updated stripes-react-hotkeys * consistently use renderprops for CellMeasurer * Update CHANGELOG.md --- CHANGELOG.md | 4 ++ lib/Accordion/Accordion.js | 11 ++-- .../headers/DefaultAccordionHeader.js | 8 +-- .../headers/FilterAccordionHeader.js | 10 +-- .../AdvancedSearchModal.js | 6 +- lib/Commander/CommandList.js | 11 +++- lib/MetaSection/MetaAccordionHeader.js | 19 +++--- lib/MultiColumnList/CellMeasurer.js | 25 +++++--- lib/MultiColumnList/MCLRenderer.js | 63 ++++++++++--------- lib/MultiColumnList/RowMeasurer.js | 45 ++++++++++--- .../tests/MultiColumnList-test.js | 2 +- package.json | 2 +- yarn.lock | 8 +-- 13 files changed, 135 insertions(+), 79 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 828e6cded..73454122b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,10 @@ * Apply `inert` attribute to header and siblings of `div#OverlayContainer` when modals are open. Refs STCOM-1334. * Expand focus trapping of modal to the `div#OverlayContainer` so that overlay components can function within `` using the `usePortal` prop. Refs STCOM-1334. * Render string for `FilterGroups` clear button. Refs STCOM-1337. +* Refactored away from `findDOMNode` in codebase for React 19 preparation. Refs STCOM-1343. +* AdvancedSearch - added a wrapping div to ref for a HotKeys ref. Refs STCOM-1343. +* `` components `` and `` updated to use refs vs `findDOMNode`. Refs STCOM-1343. +* `` are wrapped with a div for use as a HotKeys ref. Refs STCOM-1343. ## [12.1.0](https://github.com/folio-org/stripes-components/tree/v12.1.0) (2024-03-12) [Full Changelog](https://github.com/folio-org/stripes-components/compare/v12.0.0...v12.1.0) diff --git a/lib/Accordion/Accordion.js b/lib/Accordion/Accordion.js index 33382fcf2..77c8c0cf7 100644 --- a/lib/Accordion/Accordion.js +++ b/lib/Accordion/Accordion.js @@ -26,7 +26,7 @@ const propTypes = { disabled: PropTypes.bool, displayWhenClosed: PropTypes.element, // eslint-disable-line react/no-unused-prop-types displayWhenOpen: PropTypes.element, // eslint-disable-line react/no-unused-prop-types - header: PropTypes.oneOfType([PropTypes.node, PropTypes.string, PropTypes.func]), + header: PropTypes.elementType, headerProps: PropTypes.object, id: PropTypes.string, label: PropTypes.oneOfType([ // eslint-disable-line react/no-unused-prop-types @@ -120,7 +120,7 @@ const Accordion = (props) => { const contentId = useRef(contentIdProp || uniqueId('accordion')).current; const trackingId = useRef(id || uniqueId('acc')).current; const labelId = useRef(headerProps?.labelId || `accordion-toggle-button-${trackingId}`).current; - + const headerRef = useRef(null); const getRef = useRef(() => toggle.current).current; const [isOpen, updateOpen] = useState(open || !closedByDefault); @@ -139,7 +139,7 @@ const Accordion = (props) => { if (!focused) { updateFocused(true); updateZIndex((cur) => { - if(content.current.matches(':focus-within')) { + if (content.current.matches(':focus-within')) { // we assign one greater than the highest z-index value. const highest = getHighestStackOrder() + 1; if (cur !== highest) { @@ -215,9 +215,12 @@ const Accordion = (props) => { id={`${trackingId}-hotkeys`} keyMap={toggleKeyMap} handlers={toggleKeyHandlers} + attach={headerRef.current} noWrapper > - {headerElement} +
+ {headerElement} +
{ +const DefaultAccordionHeader = forwardRef(({ headerProps = { headingLevel: 3 }, ...rest }, ref) => { const props = { headerProps, ...rest }; function handleHeaderClick(e) { const { id, label } = props; @@ -52,7 +52,7 @@ const DefaultAccordionHeader = ({ headerProps = { headingLevel: 3 }, ...rest }) } return ( -
+