-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[Chip] Add clickable
property
#11613
Changes from 6 commits
067e968
ce3d7bb
550f728
c0c4114
fd65f3a
77d4424
f834c8a
ac3ed14
8a0645d
0a9867f
7bd5c43
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,6 +131,7 @@ class Chip extends React.Component { | |
avatar: avatarProp, | ||
classes, | ||
className: classNameProp, | ||
clickable, | ||
component: Component, | ||
deleteIcon: deleteIconProp, | ||
label, | ||
|
@@ -143,7 +144,7 @@ class Chip extends React.Component { | |
|
||
const className = classNames( | ||
classes.root, | ||
{ [classes.clickable]: onClick }, | ||
{ [classes.clickable]: onClick || clickable }, | ||
{ [classes.deletable]: onDelete }, | ||
classNameProp, | ||
); | ||
|
@@ -209,6 +210,12 @@ Chip.propTypes = { | |
* @ignore | ||
*/ | ||
className: PropTypes.string, | ||
/** | ||
* If true, the chip will appear clickable, and will raise when pressed, | ||
* even if the onClick property is not defined. This can be used, for example, | ||
* along with the component property to indicate an anchor Chip is clickable. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming we keep the current logic, the wording needs to be something like: "If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And an example in the docs would be good... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mbrookes Have changed the comments and added an example as well. Please let me know if any other changes are required |
||
clickable: PropTypes.bool, | ||
/** | ||
* The component used for the root node. | ||
* Either a string to use a DOM element or a component. | ||
|
@@ -242,6 +249,7 @@ Chip.propTypes = { | |
}; | ||
|
||
Chip.defaultProps = { | ||
clickable: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @oliviertassinari I feel clickable should have low priority than OnClick. The output of above will still be clickable as per the below code: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @oliviertassinari This is only affecting the styling (and the description should perhaps reflect that), but requiring the prop to be set in order for a Chip with onClick to appear clickable seems counter-intuitive to me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@mbrookes I was asking the question in a context where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see. So being able to set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @oliviertassinari I feel defaultProps.clickable = null also would work fine. still false makes better sense, as we have kept props type as boolean. Also, in terms of functionality, nothing changes in either way There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mbrookes Couldn't understand your question clearly. But to explain, if we have 'onClick' hander, 'clickable' doesn't affect and the chip is always clickable. when 'onClick' is not present, then the value of 'clickable' determine if the chip is clickable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vilvaathibanpb I was just clarifying with @oliviertassinari if I understood correctly the benefit of Let me rephrase it as a direct question: @oliviertassinari What do you see as the main benefit for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The advantage is that it's allowing people to control the clickable state, but still, being able to rely on the onClick detection logic if they wish. But I'm fine either way. The current approach is simple too. |
||
component: 'div', | ||
}; | ||
|
||
|
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.
@mbrookes Unless I'm missing something, by demo, the point was to showcase a link chip no?
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.
Yes. For buttons we link to the page section id, so a link to '#chip' would do.
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.
Got it. you also want me to add component 'a' ? or just adding a 'href="#chip"' will do? And what title will be suitable for it? "Link" or "Clickable without onClick chip (Link)".
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.
Whatever use case you're solving for, and as short a name as possible.
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.
@mbrookes I have added link to the Chip and also made the name as Clickable Link Chip. Please let me know if I have to make any more changes