Skip to content

Conversation

@CalamityC
Copy link
Contributor

add focus handling to RelatedAgreementField

@github-actions
Copy link

License CLA Stuck? (Developer should make sure that it is really stuck before clicking)

@github-actions
Copy link

github-actions bot commented Dec 17, 2025

Jest Unit Test Results

    1 files  ±0    180 suites  +1   4m 36s ⏱️ +24s
1 495 tests +3  1 495 ✅ +3  0 💤 ±0  0 ❌ ±0 
1 501 runs  +3  1 501 ✅ +3  0 💤 ±0  0 ❌ ±0 

Results for commit 50d25ad. ± Comparison against base commit 394935f.

♻️ This comment has been updated with latest results.

@sonarqubecloud
Copy link

@CalamityC CalamityC marked this pull request as ready for review December 17, 2025 16:07
Copy link
Contributor

@EthanFreestone EthanFreestone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CalamityC Thanks for the proposal here, I think this reinforces what I was hoping not to have to do on the call, but I think we need a more generic way of handling the

  • form array new clicked
  • focus on element
    pattern

'buttonRef': triggerButton,
'buttonStyle': value ? 'default' : 'primary',
'id': `${id}-find-agreement-btn`,
'id': triggerButtonId || `${id}-find-agreement-btn`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we already have a ref, I'm not sure why we need to append a custom id and then focus by that id


const { selfLinkedWarning, setSelfLinkedWarning } = useLinkedWarning(change, input, parentAgreementId, triggerButton);

useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems ok to me on first pass, but I do wonder if we're manually doing this on mount whether we're missing something.

useEffect on mount here I think means that if we decided to open the form up with an empty field instead of none (like periods in agreements) then this would focus.

Whereas what we're actually after is the focusing as a byproduct of being added...

I think alltold this probably should be dealt with more holistically.

Something like

const { focusRef, addCallback } useAddElementFocus

which we can implement within form components, and on creation of a new object handles the focusing of the ref

OR some kind of handling in form arrays specifically, where it internally tracks state, and on addition it can move focus to the new element...

Either way I think controlling from the overview of all elements makes more sense than each element controlling whether it gets focus or not.

@@ -0,0 +1,9 @@
const focusByIdWhenReady = (id) => {
requestAnimationFrame(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be using animationFrames like this.

If we need to wait for a ref to be filled, we can use a callback ref and check whether the current is null or not

@@ -0,0 +1,28 @@
import refdata from './refdata';

export const relatedAgreements = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm reading this right this is just a list of agreements. We should either use the agreements already in the centralised agreements resource, or add these to that list and extract by name/id in the test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants