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

[RFR] Fix ReferenceField in Datagrids using rowClick #2457

Merged
merged 1 commit into from
Oct 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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