Skip to content

fixing combobox to use useFormProps and related component refactors#2351

Merged
ktabors merged 4 commits into
mainfrom
combobox_useformprops
Oct 25, 2021
Merged

fixing combobox to use useFormProps and related component refactors#2351
ktabors merged 4 commits into
mainfrom
combobox_useformprops

Conversation

@ktabors
Copy link
Copy Markdown
Collaborator

@ktabors ktabors commented Sep 17, 2021

Closes #2323

Added useFormProps to Field so all form components have it. Audited its usage, removed in a couple places and left in a couple.

#2334 was exists to make a Chromatic baseline to fully test this.

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

run chromatic and the changes should be that combobox works better in form.

Test all components that use Field because useFormProps was added which means all its children were updated.
Explicitly changed NumberField, Picker, SearchWithin, and TextFieldBase.

Check the form and provider stories.

🧢 Your Project:

RSP

@adobe-bot
Copy link
Copy Markdown

Build successful! 🎉

Copy link
Copy Markdown
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

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

The other components look good to me, just one thing w/ mobile combobox

Comment thread packages/@react-spectrum/label/src/Field.tsx
@adobe-bot
Copy link
Copy Markdown

Build successful! 🎉

@ktabors
Copy link
Copy Markdown
Collaborator Author

ktabors commented Sep 22, 2021

Reviewed the chromatic and the only updates are combobox side label and necessity indicator working.

https://www.chromatic.com/build?appId=5f0dd5ad2b5fc10022a2e320&number=136

@adobe-bot
Copy link
Copy Markdown

Build successful! 🎉

}

function TextFieldBase(props: TextFieldBaseProps, ref: Ref<TextFieldRef>) {
props = useProviderProps(props);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

how'd we remove useProviderProps from this one? but not from SearchWithin?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

useProviderProps is useful for a component that is being rendered directly like SearchWithin. If it is a child like TextFieldBase which other components use as a child, this call doesn't do anything. And useProviderProps can't exist here and not in the parent. useProviderProps must be in the parent. It we had Storybook tests of TextFieldBase we would need this useProviderProps call.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IMO I think we are ok pulling useProviderProps from TextFieldBase, feels like calling that hook is something each parent component that uses TextFieldBase should handle (e.g. if a component needs to override one of the provider props).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

On second thought, useProviderProps favors the provided props over the props from the Provider so perhaps it would make sense to keep useProviderProps in TextFieldBase and remove it from the parent components that use it?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Just to remind myself, I move useProviderProps from TextField to TextFieldBase. I goto the form stories, things look good until I get to isDsiabled, TextField is not disabled. Same in the provider stories. This might be a bug with isDisabled.

Looking at SearchWithin it seems like it shouldn't need useProviderProps, but when I remove it isDisabled breaks (which is weird, because I'd expect SearchField to pick it up) and the required indicator stops working.

I think there is a bug. I'm debugging the code and found that calling useProviderProps({}) in SearchField returns

isDisabled: true
isEmphasized: undefined
isQuiet: undefined
isReadOnly: undefined
isRequired: undefined
validationState: undefined

but calling the props after props = useProviderProps(props); still have isDsiabled as undefined.

UNSAFE_className: "searchwithin_spectrum-SearchWithin-searchfield_9a8c2"
aria-label: undefined
aria-labelledby: "react-aria489618031-2628"
id: "react-aria489618031-2627"
isDisabled: undefined
isEmphasized: undefined
isQuiet: false
isReadOnly: undefined
isRequired: undefined
label: null
placeholder: "Search"
validationState: null

Copy link
Copy Markdown
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

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

LGTM provided we are ok with pulling useProviderProps out of TextFieldBase. Left comment in that thread

Copy link
Copy Markdown
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

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

Looks good, do we need any tests? or do we have tests that cover these?

@ktabors
Copy link
Copy Markdown
Collaborator Author

ktabors commented Oct 25, 2021

Looks good, do we need any tests? or do we have tests that cover these?

I assumed we had tests that confirmed these props were making it to children, but if we didn't catch this in combobox. Maybe I should have a story in form and provider that looks at all the form inputs similar to the storybook stories.

We do have this covered in chromatic now.

@snowystinger
Copy link
Copy Markdown
Member

That's true, chromatic would cover these now, thanks!

@adobe-bot
Copy link
Copy Markdown

Build successful! 🎉

@ktabors ktabors merged commit bd8c099 into main Oct 25, 2021
@ktabors ktabors deleted the combobox_useformprops branch October 25, 2021 19:31
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.

ComboBox Form context inheritance issue with label props

4 participants