pnp / pnp/sp-dev-fx-controls-react
Custom onClick on FieldTitleRenderer fails with error if id is unspecified
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 433
- Forks
- 418
- Avg merge
- 5d 6m
- Merged PRs (30d)
- 19
Description
Category
[ ] Enhancement
[X] Bug
[ ] Question
Version
3.6.0
Expected / Desired Behavior / Question
The [documentation] for FieldTitleRenderer states that the listId and id props are only required if onClick is not defined.
This means that it should be possible to use a custom onClick handler even if listId and id are unspecified.
Observed Behavior
The onClick handler fails with an error under these circumstances:
Uncaught TypeError: Cannot read properties of undefined (reading 'toString')
This is happening due to a breaking change that was made 5 months ago.
Before change:
if (this.props.onClick) {
const args: IFieldTitleClickEventArgs = this.props as IFieldTitleClickEventArgs;
this.props.onClick(args);
return;
}
After change:
if (this.props.onClick) {
const args: IFieldTitleClickEventArgs = {
listId: this.props.listId,
id: this.props.id.toString()
};
this.props.onClick(args);
return;
}
As you can see here, the "after" code is attempting to access this.props.id.toString(), which will fail with an error if this.props.id is unspecified.
Steps to Reproduce
- Create or find a field customizer that uses a
FieldTitleRenderer - In the
FieldTitleRenderer's props, specify anonClickhandler but noidprop - View the field customizer and attempt to click the item in question
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the FieldTitleRenderer implementation and compare its custom onClick path with the documented optional listId and id props. Reproduce the field customizer case with onClick but no id, then verify the handler works without the toString error and that existing behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100