Skip to content

Commit

Permalink
Merge pull request #2457 from marmelab/referencefield-rowclick
Browse files Browse the repository at this point in the history
[RFR] Fix ReferenceField in Datagrids using rowClick
  • Loading branch information
Gildas Garcia authored Oct 22, 2018
2 parents 18fcad8 + a54acf0 commit 8c5fc55
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/ra-ui-materialui/src/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const styles = theme => ({
/**
* @deprecated Use react-router-dom's Link instead
*/
const Link = ({ to, children, className, classes }) => (
<RRLink to={to} className={classNames(classes.link, className)}>
const Link = ({ to, children, className, classes, ...rest }) => (
<RRLink to={to} className={classNames(classes.link, className)} {...rest}>
{children}
</RRLink>
);
Expand Down
9 changes: 8 additions & 1 deletion packages/ra-ui-materialui/src/field/ReferenceField.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const styles = theme => ({
},
});

// useful to prevent click bubbling in a datagrid with rowClick
const stopPropagation = e => e.stopPropagation();

export const ReferenceFieldView = ({
allowEmpty,
basePath,
Expand All @@ -36,7 +39,11 @@ export const ReferenceFieldView = ({

if (resourceLinkPath) {
return (
<Link to={resourceLinkPath} className={className}>
<Link
to={resourceLinkPath}
className={className}
onClick={stopPropagation}
>
{React.cloneElement(children, {
className: classnames(
children.props.className,
Expand Down
6 changes: 5 additions & 1 deletion packages/ra-ui-materialui/src/list/SingleFieldList.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const styles = {
root: { display: 'flex', flexWrap: 'wrap' },
};

// useful to prevent click bubbling in a datagrid with rowClick
const stopPropagation = e => e.stopPropagation();

const sanitizeRestProps = ({ currentSort, setSort, isLoading, ...props }) =>
props;

Expand All @@ -22,7 +25,7 @@ const sanitizeRestProps = ({ currentSort, setSort, isLoading, ...props }) =>
* <ChipField source="title" />
* </SingleFieldList>
* </ReferenceManyField>
*
*
* By default, it includes a link to the <Edit> page of the related record
* (`/books/:id` in the previous example).
*
Expand Down Expand Up @@ -79,6 +82,7 @@ export class SingleFieldList extends Component {
className={classnames(classes.link, className)}
key={id}
to={resourceLinkPath}
onClick={stopPropagation}
>
{cloneElement(children, {
record: data[id],
Expand Down

0 comments on commit 8c5fc55

Please sign in to comment.