Skip to content
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
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ITextField, ITextFieldProps } from './TextField.types';
import { Label } from '../../Label';
import { Icon } from '../../Icon';
import {
autobind,
DelayedRender,
BaseComponent,
getId,
Expand Down Expand Up @@ -150,7 +149,8 @@ export class TextField extends BaseComponent<ITextFieldProps, ITextFieldState> 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;
Expand Down Expand Up @@ -192,7 +192,7 @@ export class TextField extends BaseComponent<ITextFieldProps, ITextFieldState> i
</div>
{ this._isDescriptionAvailable &&
<span id={ this._descriptionId }>
{ description && <span className={ css('ms-TextField-description', styles.description) }>{ description }</span> }
{ onRenderDescription(this.props, this._onRenderDescription) }
{ errorMessage &&
<div aria-live='assertive'>
<DelayedRender>
Expand Down Expand Up @@ -293,13 +293,16 @@ export class TextField extends BaseComponent<ITextFieldProps, ITextFieldState> i
}
}

@autobind
private _onRenderLabel(props: ITextFieldProps): JSX.Element | null {
const {
label
} = props;
if (label) {
return (<Label htmlFor={ this._id }>{ label }</Label>);
private _onRenderLabel = (props: ITextFieldProps): JSX.Element | null => {
if (props.label) {
return (<Label htmlFor={ this._id }>{ props.label }</Label>);
}
return null;
}

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

return (<span className={ css('ms-TextField-description', styles.description) }>{ props.description }</span>);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export interface ITextFieldProps extends React.AllHTMLAttributes<HTMLInputElemen
label?: string;

/**
* Optional custom renderer for the label
* Optional custom renderer for the label.
*/
onRenderLabel?: IRenderFunction<ITextFieldProps>;

Expand All @@ -87,6 +87,11 @@ export interface ITextFieldProps extends React.AllHTMLAttributes<HTMLInputElemen
*/
description?: string;

/**
* Optional custom renderer for the description.
*/
onRenderDescription?: IRenderFunction<ITextFieldProps>;

/**
* @deprecated
* Deprecated; use prefix instead.
Expand All @@ -110,12 +115,12 @@ export interface ITextFieldProps extends React.AllHTMLAttributes<HTMLInputElemen
onRenderAddon?: IRenderFunction<ITextFieldProps>;

/**
* Custom render function for prefix
* Custom render function for prefix.
*/
onRenderPrefix?: IRenderFunction<ITextFieldProps>;

/**
* Custom render function for suffix
* Custom render function for suffix.
*/
onRenderSuffix?: IRenderFunction<ITextFieldProps>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<IComponentDemoPageProps, {}> {
public render() {
Expand Down Expand Up @@ -111,6 +113,12 @@ export class TextFieldPage extends React.Component<IComponentDemoPageProps, {}>
>
<TextFieldCustomRenderExample />
</ExampleCard>
<ExampleCard
title='TextField with custom description'
code={ TextFieldOnRenderDescriptionExampleCode }
>
<TextFieldOnRenderDescriptionExample />
</ExampleCard>
<ExampleCard
title='TextField error message variations'
code={ TextFieldErrorMessageExampleCode }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as React from 'react';
import { TextField, ITextFieldProps } from 'office-ui-fabric-react/lib/TextField';
import './TextField.Examples.scss';

export class TextFieldOnRenderDescriptionExample extends React.Component<{}, {}> {
public render() {
return (
<div className='docs-TextFieldExample'>
<TextField
description={ 'A custom description that appends a link.' }
onRenderDescription={ this._onRenderDescription }
/>
</div>
);
}

private _onRenderDescription = (props: ITextFieldProps): JSX.Element => {
return (
<div>
{ props.description }{ ' ' }
<a href='#' onClick={ this._onLinkClick } >Link</a>
</div>);
}

private _onLinkClick = (e: React.MouseEvent<HTMLElement>) => {
e.preventDefault();
}
}