Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add autoFocus to RadioButton #2057

Merged

Conversation

chensara
Copy link
Contributor

@chensara chensara commented Apr 10, 2024

In the new hard signup we want to autofocus the first option for each question in order to support accesibility and voice reading in the future: see -> task item
So for this reason, I added autoFocus prop to RadioButton

@chensara chensara requested a review from a team as a code owner April 10, 2024 10:22
@@ -114,6 +127,7 @@ const RadioButton: VibeComponent<RadioButtonProps, HTMLElement> & object = forwa
type="radio"
value={value}
name={name}
autoFocus={autoFocus}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if both methods are needed, the useEffect and the autoFocus.
I know that TextField implements it using the useEffect with the animation frame, which I guess is for a reason.
@talkor wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

Both should work but IMO it's better to just use the autoFocus prop which is an HTML attribute which makes the useEffect redundant in this case

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, and it does work on Storybook, but they might implemented the useEffect as in some scenarios possibly there was a render issue requiring this to be on the next animation frame?
not sure

Copy link
Contributor

Choose a reason for hiding this comment

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

@chensara let's do the following
use the native autoFocus instead of the useEffect.

  • let's release a prerelease
  • or just use yarn pack on monday-ui-react-core's packages/core and use it in your local version
  • you can also use yarn link, which is better IMO, with your MF.
    Make sure that you run the command using the same node version that is used on your MF, in Vibe we're using node v18.12.1
    Also make sure to run yarn link monday-ui-react-core afterwards on your MF of course
    Notice in this case that you need to run yarn build for every change to take effect on your MF

if it works for you with the native approach, amazing. if not, try the same with the useEffect

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I first implemented using only autoFocus attr but it doesn't work in stroybook so I added the useEffect and it worked. Should I delete autoFocus attr?

Copy link
Contributor

Choose a reason for hiding this comment

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

when I've checked with the autoFocus it seems like working

@@ -64,6 +66,7 @@ const RadioButton: VibeComponent<RadioButtonProps, HTMLElement> & object = forwa
*/
radioButtonClassName,
disabled = false,
autoFocus = false,
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe leave it undefined in case it isn't supplied
so current snapshots won't add autoFocus=false to their snapshots, as it can lead to - when upgrading a version in monolith - to multiple snapshots being broken
we're ok with it as undefined
so just remove the default false

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed :)

Comment on lines 18 to 22
const radiosName = "radios";

beforeEach(() => {
onChangeMock1 = jest.fn();
onChangeMock2 = jest.fn();
onChangeMock3 = jest.fn();
const option1Value = "1";
const option2Value = "2";
const option3Value = "3";
Copy link
Contributor

@YossiSaadi YossiSaadi Apr 10, 2024

Choose a reason for hiding this comment

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

I'm not sure about inserting the *Value inside, and also about radiosName, sounds like they can lay outside of this block (even in the top of the file, outside of any block, but they can just get back to where they were before)
did something not worked for you while they were there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@YossiSaadi YossiSaadi left a comment

Choose a reason for hiding this comment

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

Looks awesome! congrats on your first contribution to Vibe! 🎉

@YossiSaadi YossiSaadi merged commit d40b49e into mondaycom:master Apr 10, 2024
4 checks passed
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