diff --git a/common/changes/office-ui-fabric-react/onRenderDescription_for_TextField_2018-04-16-23-55.json b/common/changes/office-ui-fabric-react/onRenderDescription_for_TextField_2018-04-16-23-55.json new file mode 100644 index 00000000000000..fbfb53e7016884 --- /dev/null +++ b/common/changes/office-ui-fabric-react/onRenderDescription_for_TextField_2018-04-16-23-55.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "office-ui-fabric-react", + "comment": "add onRenderDescription to TextField", + "type": "minor" + } + ], + "packageName": "office-ui-fabric-react", + "email": "chrismo@microsoft.com" +} \ No newline at end of file diff --git a/packages/office-ui-fabric-react/src/components/TextField/TextField.tsx b/packages/office-ui-fabric-react/src/components/TextField/TextField.tsx index 309fd7ee2ca28a..a07aa059e0dfeb 100644 --- a/packages/office-ui-fabric-react/src/components/TextField/TextField.tsx +++ b/packages/office-ui-fabric-react/src/components/TextField/TextField.tsx @@ -3,7 +3,6 @@ import { ITextField, ITextFieldProps } from './TextField.types'; import { Label } from '../../Label'; import { Icon } from '../../Icon'; import { - autobind, DelayedRender, BaseComponent, getId, @@ -150,7 +149,8 @@ export class TextField extends BaseComponent i onRenderAddon = this._onRenderAddon, // @deprecated onRenderPrefix = this._onRenderPrefix, onRenderSuffix = this._onRenderSuffix, - onRenderLabel = this._onRenderLabel + onRenderLabel = this._onRenderLabel, + onRenderDescription = this._onRenderDescription } = this.props; const { isFocused } = this.state; const errorMessage = this._errorMessage; @@ -192,7 +192,7 @@ export class TextField extends BaseComponent i { this._isDescriptionAvailable && - { description && { description } } + { onRenderDescription(this.props, this._onRenderDescription) } { errorMessage &&
@@ -293,13 +293,16 @@ export class TextField extends BaseComponent i } } - @autobind - private _onRenderLabel(props: ITextFieldProps): JSX.Element | null { - const { - label - } = props; - if (label) { - return (); + private _onRenderLabel = (props: ITextFieldProps): JSX.Element | null => { + if (props.label) { + return (); + } + return null; + } + + private _onRenderDescription = (props: ITextFieldProps): JSX.Element | null => { + if (props.description) { + return ({ props.description }); } return null; } diff --git a/packages/office-ui-fabric-react/src/components/TextField/TextField.types.ts b/packages/office-ui-fabric-react/src/components/TextField/TextField.types.ts index 41d6d0bf120031..6ed2c850c5f721 100644 --- a/packages/office-ui-fabric-react/src/components/TextField/TextField.types.ts +++ b/packages/office-ui-fabric-react/src/components/TextField/TextField.types.ts @@ -78,7 +78,7 @@ export interface ITextFieldProps extends React.AllHTMLAttributes; @@ -87,6 +87,11 @@ export interface ITextFieldProps extends React.AllHTMLAttributes; + /** * @deprecated * Deprecated; use prefix instead. @@ -110,12 +115,12 @@ export interface ITextFieldProps extends React.AllHTMLAttributes; /** - * Custom render function for prefix + * Custom render function for prefix. */ onRenderPrefix?: IRenderFunction; /** - * Custom render function for suffix + * Custom render function for suffix. */ onRenderSuffix?: IRenderFunction; diff --git a/packages/office-ui-fabric-react/src/components/TextField/TextFieldPage.tsx b/packages/office-ui-fabric-react/src/components/TextField/TextFieldPage.tsx index 15ebbbd00d5196..000ba49e16fb13 100644 --- a/packages/office-ui-fabric-react/src/components/TextField/TextFieldPage.tsx +++ b/packages/office-ui-fabric-react/src/components/TextField/TextFieldPage.tsx @@ -19,6 +19,7 @@ import { TextFieldStatus } from './TextField.checklist'; import { TextFieldSuffixExample } from './examples/TextField.Suffix.Example'; import { TextFieldUnderlinedExample } from './examples/TextField.Underlined.Example'; import { TextFieldAutoCompleteExample } from './examples/TextField.AutoComplete.Example'; +import { TextFieldOnRenderDescriptionExample } from './examples/TextField.OnRenderDescription.Example'; const TextFieldBasicExampleCode = require('!raw-loader!office-ui-fabric-react/src/components/TextField/examples/TextField.Basic.Example.tsx') as string; const TextFieldBorderlessExampleCode = require('!raw-loader!office-ui-fabric-react/src/components/TextField/examples/TextField.Borderless.Example.tsx') as string; @@ -32,6 +33,7 @@ const TextFieldPrefixAndSuffixExampleCode = require('!raw-loader!office-ui-fabri const TextFieldSuffixExampleCode = require('!raw-loader!office-ui-fabric-react/src/components/TextField/examples/TextField.Suffix.Example.tsx') as string; const TextFieldUnderlinedExampleCode = require('!raw-loader!office-ui-fabric-react/src/components/TextField/examples/TextField.Underlined.Example.tsx') as string; const TextFieldAutoCompleteExampleCode = require('!raw-loader!office-ui-fabric-react/src/components/TextField/examples/TextField.AutoComplete.Example.tsx') as string; +const TextFieldOnRenderDescriptionExampleCode = require('!raw-loader!office-ui-fabric-react/src/components/TextField/examples/TextField.OnRenderDescription.Example.tsx') as string; export class TextFieldPage extends React.Component { public render() { @@ -111,6 +113,12 @@ export class TextFieldPage extends React.Component > + + + { + public render() { + return ( +
+ +
+ ); + } + + private _onRenderDescription = (props: ITextFieldProps): JSX.Element => { + return ( +
+ { props.description }{ ' ' } + Link +
); + } + + private _onLinkClick = (e: React.MouseEvent) => { + e.preventDefault(); + } +}