-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
STCOM-1372 Use mutationobserver for focus management in repeatable fi…
…eld (#2376) * use mutationobserver for focusmanagement in repeatable field * cleanup RFContent, mild refactor, check for RF-items addition, deletion, specifically. * use state to check if the user has interacted with the repeatableField * add comments for conditionals * Update CHANGELOG.md
- Loading branch information
Showing
3 changed files
with
59 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,17 @@ | ||
import React, { useCallback } from "react"; | ||
import PropTypes from "prop-types"; | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { getFirstFocusable } from "../../util/getFocusableElements"; | ||
import css from './RepeatableField.css'; | ||
|
||
import css from "./RepeatableField.css"; | ||
|
||
export const RepeatableFieldContent = ({ children, isFocused }) => { | ||
|
||
const callbackRef = useCallback((node) => { | ||
if (node && isFocused) { | ||
const elem = getFirstFocusable(node, true, true); | ||
|
||
elem?.focus(); | ||
} | ||
}, [isFocused]) | ||
|
||
return ( | ||
<div className={css.repeatableFieldItemContent} ref={callbackRef}> | ||
{children} | ||
</div> | ||
); | ||
} | ||
export const RepeatableFieldContent = ({ children }) => ( | ||
<div className={css.repeatableFieldItemContent}> | ||
{children} | ||
</div> | ||
); | ||
|
||
RepeatableFieldContent.propTypes = { | ||
children: PropTypes.oneOfType([ | ||
PropTypes.node, | ||
PropTypes.func, | ||
]).isRequired, | ||
isFocused: PropTypes.bool.isRequired, | ||
} |