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

Forward ref support for TableRow, Tabs, ToggleButton & ToggleButtonGroup #861

Merged
merged 9 commits into from
Nov 29, 2021

Conversation

zchenwei
Copy link
Contributor

Description of changes:

This PR will be adding Forward ref support for TableRow, Tabs, ToggleButton & ToggleButtonGroup

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@changeset-bot
Copy link

changeset-bot bot commented Nov 23, 2021

🦋 Changeset detected

Latest commit: addb5db

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@aws-amplify/ui-react Patch
@aws-amplify/ui Patch
@aws-amplify/ui-vue Patch
@aws-amplify/ui-angular Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment on lines -35 to -36
id,
role,
Copy link
Contributor Author

@zchenwei zchenwei Nov 23, 2021

Choose a reason for hiding this comment

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

This is a bug. It basically provides undefined props and if we don't supply any value explicitly. So if we render a component like this way <View as={RadixTab} /> , both role and id specified internally by radix will be overridden and clear out, probably through {...rest} I guess.

Copy link
Contributor

Choose a reason for hiding this comment

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

So, className, role and id will be passed through the {...nonStyleProps} correct?

Copy link
Contributor Author

@zchenwei zchenwei Nov 24, 2021

Choose a reason for hiding this comment

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

Yes, exactly if they are provided. But if we list those out explicitly and not specify values for them, then it will pass in undefined. Equivalent to the following:

{
   ...
   role: undefined
   id: undefined
   ...
}

In most cases, this should be good. But passing in undefined will override underlying components' role and id setting, if they are supposed to be generated internally.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I've seen a related issue with the Radix Dropdown primitives we use in Menu where a passed className prop overrode the internal className and would break the component behavior. It looks like we have a test around id, and role but not for className. Would you mind adding a className test to View.test.tsx?

@zchenwei zchenwei temporarily deployed to ci November 23, 2021 22:15 Inactive
@zchenwei zchenwei temporarily deployed to ci November 23, 2021 22:15 Inactive
@zchenwei zchenwei temporarily deployed to ci November 23, 2021 22:15 Inactive
onChange,
indicatorPosition,
spacing,
...rest
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for cleaning this up

@zchenwei zchenwei temporarily deployed to ci November 23, 2021 22:35 Inactive
const tabs = React.Children.map(children, (child) => {
if (!isTabsType(child)) {
console.warn(
'Amplify UI: <Tabs> component only accepts <TabItem> as children.'
);
return null;
return {};
Copy link
Contributor Author

@zchenwei zchenwei Nov 23, 2021

Choose a reason for hiding this comment

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

[..., null, ...] will throw error on mapping operation. Cannot deconstruct null or reference to a prop

@zchenwei zchenwei temporarily deployed to ci November 23, 2021 23:13 Inactive
@zchenwei zchenwei temporarily deployed to ci November 23, 2021 23:13 Inactive
@zchenwei zchenwei temporarily deployed to ci November 23, 2021 23:13 Inactive
return null;
}

return React.cloneElement(child, {
Copy link
Contributor Author

@zchenwei zchenwei Nov 23, 2021

Choose a reason for hiding this comment

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

By cloning, we are able to clone the ref passed along. I cannot find a way to reference ref directly from child

@zchenwei zchenwei temporarily deployed to ci November 23, 2021 23:29 Inactive
@zchenwei zchenwei added pending-review An issue or a feature PR is pending review prior to release React An issue or a feature-request for React platform labels Nov 24, 2021
@zchenwei zchenwei temporarily deployed to ci November 24, 2021 16:17 Inactive
@zchenwei zchenwei temporarily deployed to ci November 24, 2021 16:17 Inactive
@zchenwei zchenwei temporarily deployed to ci November 24, 2021 16:17 Inactive
@zchenwei zchenwei temporarily deployed to ci November 24, 2021 16:32 Inactive
Copy link
Contributor

@reesscot reesscot 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, just want to confirm the change to View doesn't cause any regressions.

indicatorPosition,
spacing,
...rest
}: TabsProps,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
}: TabsProps,
}

packages/react/src/primitives/Tabs/Tabs.tsx Outdated Show resolved Hide resolved
ref
) => (
<View
as={RadixTab}
Copy link
Contributor

Choose a reason for hiding this comment

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

Woah, so cool that this works!

Comment on lines -35 to -36
id,
role,
Copy link
Contributor

Choose a reason for hiding this comment

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

So, className, role and id will be passed through the {...nonStyleProps} correct?

Co-authored-by: Scott Rees <6165315+reesscot@users.noreply.github.com>
@lgtm-com
Copy link

lgtm-com bot commented Nov 24, 2021

This pull request introduces 1 alert when merging aabc200 into b0985f6 - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@zchenwei zchenwei requested a review from reesscot November 24, 2021 18:50
@zchenwei zchenwei enabled auto-merge (squash) November 24, 2021 18:52
@zchenwei zchenwei temporarily deployed to ci November 24, 2021 19:05 Inactive
@zchenwei zchenwei temporarily deployed to ci November 24, 2021 19:05 Inactive
@zchenwei zchenwei temporarily deployed to ci November 24, 2021 19:05 Inactive
@zchenwei zchenwei temporarily deployed to ci November 24, 2021 19:25 Inactive
Copy link
Contributor

@reesscot reesscot left a comment

Choose a reason for hiding this comment

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

It looks like we have a View tests around id, and role but not for className. Would you mind adding a className test to View.test.tsx?

@zchenwei zchenwei requested a review from reesscot November 25, 2021 00:38
@zchenwei zchenwei temporarily deployed to ci November 25, 2021 00:46 Inactive
@zchenwei zchenwei temporarily deployed to ci November 25, 2021 00:46 Inactive
@zchenwei zchenwei temporarily deployed to ci November 25, 2021 00:46 Inactive
@zchenwei zchenwei temporarily deployed to ci November 25, 2021 01:01 Inactive
@zchenwei zchenwei disabled auto-merge November 29, 2021 17:32
@@ -107,6 +107,5 @@ export enum ComponentClassNames {
TextField = 'amplify-textfield',
ToggleButton = 'amplify-togglebutton',
ToggleButtonGroup = 'amplify-togglebuttongroup',
View = 'amplify-view',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like this is not in use anywhere? Could we remove it?

Copy link
Contributor

@reesscot reesscot left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for updating the tests.

@zchenwei zchenwei merged commit b21e3e3 into main Nov 29, 2021
@zchenwei zchenwei deleted the chenwz-ref-table branch November 29, 2021 19:41
@github-actions github-actions bot mentioned this pull request Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-review An issue or a feature PR is pending review prior to release React An issue or a feature-request for React platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants