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

Add support for style merging in mergeProps #6032

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ryo-manba
Copy link
Contributor

@ryo-manba ryo-manba commented Mar 9, 2024

Closes #2507

βœ… 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:

Add the following code to Storybook and verify that styles are merged correctly.

export const Example = () => {
  let stylePropsA = {height: '50px', width: '50px'};
  let stylePropsB =  {height: '75px', color: 'orange'};
  // Expected: {style: {height: 75px, width: 50px, color: orange}}
  let result = mergeProps({style: stylePropsA}, {style: stylePropsB});
  return (
    <div {...result}>
      example
    </div>
  );
};

🧒 Your Project:

Comment on lines -24 to +26
let {elementType: ElementType = 'div', style, draggable, ...otherProps} = props;
let {elementType: ElementType = 'div', draggable, ...otherProps} = props;
let {pressProps} = usePress(otherProps);
return <ElementType {...pressProps} style={style} tabIndex="0" draggable={draggable}>{ElementType !== 'input' ? 'test' : undefined}</ElementType>;
return <ElementType {...pressProps} tabIndex="0" draggable={draggable}>{ElementType !== 'input' ? 'test' : undefined}</ElementType>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -12,7 +12,7 @@

import clsx from 'clsx';
import {mergeIds} from '../src/useId';
import {mergeProps} from '../';
import {mergeProps} from '../src/mergeProps';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed the import path because the changes were not reflected after saving.

@ryo-manba ryo-manba marked this pull request as draft March 9, 2024 14:39
@ryo-manba ryo-manba marked this pull request as ready for review March 9, 2024 14:49
Copy link
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.

@devongovett
Copy link
Member

I think one could argue this is a breaking change as well. At this point, people might be relying on the fact that styles are not merged.

@snowystinger
Copy link
Member

I think one could argue this is a breaking change as well. At this point, people might be relying on the fact that styles are not merged.

This is a good point. If it suddenly started merging, people could suddenly have extra styles coming through.

Do we actually want to do this? we could add an argument that describes how to merge the props, either a simple boolean for merge styles, or more complex, a method to give control of the merge...

Unless we do it by default though, it doesn't really help with instances such as #2457 (comment) because the user has to realize that there two competing style objects.

We'd discussed a version of mergeProps which does memo'ing, maybe we handle it there? waves hands towards the future

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.

mergeProps should combine styles
3 participants