Skip to content

add onRenderDescription to TextField#4588

Merged
dzearing merged 7 commits intomicrosoft:masterfrom
chrismohr:onRenderDescription_for_TextField
Apr 20, 2018
Merged

add onRenderDescription to TextField#4588
dzearing merged 7 commits intomicrosoft:masterfrom
chrismohr:onRenderDescription_for_TextField

Conversation

@chrismohr
Copy link
Copy Markdown
Contributor

Pull request checklist

  • Include a change request file using $ npm run change

Description of changes

Add onRenderDescription to TextField. Since description only takes a string, this allows us to render a description with additional markup, like a link for example.

(This pr replaces #4576)

}

@autobind
private _onRenderDescription(props: ITextFieldProps): JSX.Element | null {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we've moving away from autobind to arrow functions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I've made the change

description?: string;

/**
* Optional custom renderer for the description
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

description [](start = 38, length = 11)

nit: . at the end of the sentence.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

/**
* Optional custom renderer for the description
*/
onRenderDescription?: IRenderFunction<ITextFieldProps>;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onRenderDescription [](start = 2, length = 19)

Please add this along with the rest of the onRender APIs below

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added periods to the descriptions of all onRender.... functions

return null;
}

private _onRenderDescription = (props: ITextFieldProps): JSX.Element | null => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null [](start = 73, length = 4)

undefined

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manishgarg1 I've updated both _onRenderDescription and _onRenderLabel.

A bit different than you suggested though. Rather than replacing null with undefined, I was able to remove null from the return type by moving the guard into the render method.
(I wasn't sure for the motivation behind your suggestion, so please let me know if I missed the point.)

The reason I did it this way was because changing null to undefined on the return type resulted in the following error at the onRenderLabel invokation, which I don't yet understand.

[ts] Cannot invoke an expression whose type lacks a call signature. Type 'IRenderFunction<ITextFieldProps> | ((props: ITextFieldProps) => Element | undefined)' has no compatible call signatures.
const onRenderLabel: IRenderFunction<ITextFieldProps> | ((props: ITextFieldProps) => JSX.Element | undefined)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manishgarg1 On further consideration, I don't think what I did will work for us. We'd want the provided onRenderDescription to be invoked even when description is absent. I've reverted this last change.

If you still think null should be changed to undefined, can you please help me understand the motivation? And suggest a course of action given the error that I encountered above?

@manishgarg1
Copy link
Copy Markdown
Collaborator

private _onRenderLabel(props: ITextFieldProps): JSX.Element | null {

please change to undefined


Refers to: packages/office-ui-fabric-react/src/components/TextField/TextField.tsx:298 in 5f6ad33. [](commit_id = 5f6ad33, deletion_comment = False)

if (description) {
return (<span className={ css('ms-TextField-description', styles.description) }>{ description }</span>);
}
return null;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following code will do the same

return description && <span....>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slight challenge here was that we'd have to add string to the return type, because of falsey empty strings.

@manishgarg1 manishgarg1 self-assigned this Apr 17, 2018
@swese44
Copy link
Copy Markdown
Contributor

swese44 commented Apr 18, 2018

i wonder if it would be simpler to allow description to be string | JSX?

@micahgodbolt
Copy link
Copy Markdown
Member

Yeah, I was thinking about that option as well. I think for consistency an onRender isn't a bad choice though.

@swese44
Copy link
Copy Markdown
Contributor

swese44 commented Apr 18, 2018

👍

@chrismohr
Copy link
Copy Markdown
Contributor Author

Yeah, I'm open to either. Did onRender to match what was there for label, prefix etc.

}

private _onRenderDescription = (props: ITextFieldProps): JSX.Element | null => {
if (props.description) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we update this to be able to call the onRenderDescription prop even if the description prop is not provided? i think for our use case we'd like our wrapping TextField component to provide onRenderDescription without providing description since our description will allow JSX and cannot be passed in to the Fabric description

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah i see you already implemented this change within render

@dzearing dzearing closed this Apr 19, 2018
@dzearing dzearing reopened this Apr 19, 2018
@chrismohr
Copy link
Copy Markdown
Contributor Author

@micahgodbolt, @dzearing, since I haven't heard back from @manishgarg1 yet, can one of you review/approve please?

@dzearing dzearing merged commit 5cab1cf into microsoft:master Apr 20, 2018
@microsoft microsoft locked as resolved and limited conversation to collaborators Aug 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants