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: Allow props prefixed by "data-" to be rendered as attributes in picker's option elements #5871

Merged

Conversation

cgmonte
Copy link
Member

@cgmonte cgmonte commented Sep 12, 2024

Jira tasks

Main task: https://liferay.atlassian.net/browse/LPD-32878
Sub-task: https://liferay.atlassian.net/browse/LPD-35826

Introduction

The main Jira ticket above is a Liferay's DDM Form task to add data-option-reference attributes to option elements in Form's DOM.

It worked without having to modify Clay in all of the following Form field types: Grid, Multiple Select, Single Select and Multiple Select from List, which is not yet merged.

But the Single Select from List field type did not work because, currently, Option's props are specifically destructured, without assigning remaining props to something like an otherProps object.

Goal

This PR seeks to allow props prefixed by "data-" to be rendered as attributes in picker's option elements.

Issues

While developing, after allowing other props to be passed down to option elements, not only the data-option-reference attribute was rendered, but also a index appeared in the option. This happens because useCollection() adds that to DynamicCollection items. To prevent that, which did not seem right, a filter was added to otherProps to programmatically remove object keys not starting to "data-". A unity test was added to check for this case as well.

Copy link
Member

@matuzalemsteles matuzalemsteles left a comment

Choose a reason for hiding this comment

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

@cgmonte thanks for the contribution.

packages/clay-core/src/picker/Option.tsx Outdated Show resolved Hide resolved
@cgmonte
Copy link
Member Author

cgmonte commented Sep 13, 2024

Hey @matuzalemsteles, I have pushed a new version. I have excluded both the type declaration, because of what I described here, and the runtime filter you mentioned here. Problem is: because useCollection() adds an index prop that is passed together with the added otherProps, snapshots had to be updated. This will break other unity tests based on snapshots in the Portal as well.

@cgmonte
Copy link
Member Author

cgmonte commented Sep 13, 2024

I don't think this is the final solution, and having that index in the DOM doesn't seem right. It wasn't meant to be there. But I am sending this so we can discuss other options.

@matuzalemsteles
Copy link
Member

I sent a commit to remove the index from the DOM is safe now. We use it internally to calculate other things and the component needs to ignore them.

Well, regarding JS, I don't consider runtime prop validations in components to be very useful. It won't help much, even when passing the wrong value. That's why we avoid it for components nowadays. It doesn't have a valuable benefit, especially when TS is used more today and we also want people in DXP to use TS more than JS. In this specific case, I still don't think we need validation.

Copy link
Member

@matuzalemsteles matuzalemsteles left a comment

Choose a reason for hiding this comment

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

LGTM

@matuzalemsteles matuzalemsteles merged commit bfc983e into liferay:master Sep 13, 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.

2 participants