-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
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
[ListItem] Documents containerElement, changes ref to use callback #6204
Conversation
- Makes updates to make it clear how to wrap a ListItem with a link. - Using a string for refs is deprecated and was giving me a warning about putting a ref on a functional component in some cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We miss a unit test. Otherwise, it looks good 👍 .
src/List/ListItem.js
Outdated
{...other} | ||
containerElement={containerElement} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move containerElement={containerElement}
before the {...other}
just for explicitness. Users should be able to overrides everything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's overridden by simply giving a containerElement
prop. It's pulled out from the other
props because it was being passed on to the label or disabled element if it wasn't pulled out. There's no logic where anything in other
would be overriding containerElement
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lourd That's going to work the same, yes. My point was just around code readability.
Thanks for reviewing so quickly! Do you mean to say a unit test is failing because of this, or it's missing coverage? If you can point out where to add it and look at other tests for reference I'll add it. |
It's missing coverage. We don't have much on the |
src/List/ListItem.js
Outdated
@@ -154,6 +154,17 @@ class ListItem extends Component { | |||
*/ | |||
children: PropTypes.node, | |||
/** | |||
* The element to use as the container for the ListItem inside of. Either a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"inside of." ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😅 it was late
Added a couple tests and switched those lines. |
src/List/ListItem.spec.js
Outdated
assert.ok(button.is('a'), 'should match an a element'); | ||
}); | ||
|
||
it('Should use the given ReactElement containerElement', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small typo should
.
src/List/ListItem.spec.js
Outdated
/> | ||
); | ||
const button = wrapper.find(EnhancedButton).dive({context: {muiTheme}}); | ||
assert.ok(button.is('a'), 'should match an a element'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is
returns a boolean, using strictEqual
would be better than a truthy.
src/List/ListItem.spec.js
Outdated
@@ -201,4 +201,29 @@ describe('<ListItem />', () => { | |||
assert.strictEqual(wrapper.state().hovered, false, 'should reset the state'); | |||
}); | |||
}); | |||
|
|||
describe('containerElement', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a convention where we prefix the name with prop:
to describe the property expectations.
src/List/ListItem.spec.js
Outdated
/> | ||
); | ||
const button = wrapper.find(EnhancedButton).dive({context: {muiTheme}}); | ||
assert.strictEqual(button.is('a'), 'should match an a element'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert.strictEqual(button.is('a'), true, 'should match an a element');
src/List/ListItem.spec.js
Outdated
/> | ||
); | ||
const button = wrapper.find(EnhancedButton).dive({context: {muiTheme}}); | ||
assert.strictEqual(button.is(CustomElement), 'should match the custom element'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert.strictEqual(button.is(CustomElement), true, 'should match the custom element');
Thanks for documenting that property. It's such a useful one. |
- react-intl left out to use jeremy's fork. - react-router has a major version change, requires a separate commit. - material-ui has minor changes which requires snapshot changes - see mui/material-ui#6135 mui/material-ui#6204
- react-intl left out to use jeremy's fork. - react-router has a major version change, requires a separate commit. - material-ui has minor changes which requires snapshot changes - see mui/material-ui#6135 mui/material-ui#6204
about putting a ref on a functional component in some cases.