fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

conditionally hide icon button

Open russgove opened this issue 8 years ago • 2 comments

Hi , I have a component as follows import * as React from 'react'; import { TextField, ITextFieldProps } from "office-ui-fabric-react/lib/TextField"; import { IconButton } from "office-ui-fabric-react/lib/Button"; export interface ITextFieldWithEditProps { value: string; onValueChanged?: (oldValue, newValue) => void; dangerouslySetInnerHTML?:boolean; } export class TextFieldWithEdit extends React.Component<ITectFieldWithEditProps, {}>{

public render() {
    let textFieldProps: ITextFieldProps = { value: this.props.value };
    debugger;
    return (
        <div>
            <div dangerouslySetInnerHTML={{ __html: this.props.value }} />
           
            <IconButton iconProps={{iconName:"Edit"}} hidden={(this.props.onValueChanged===undefined)} />

        </div>

    );
}

}

I want to hide the icon button if the caller did not pass in a value for the onValueChanged property. the code above does not work, How can I conditionally hode an IconButton? doesnt seem to be a hidden prop.

russgove avatar Jan 10 '18 02:01 russgove

You can hide it using conditional rendering: {this.props.onValueChanged && <IconButton iconProps={{iconName:"Edit"}} />}

nse7ens avatar Jan 10 '18 07:01 nse7ens

this is definitely the proper solution. don't render the icon if your check if false. closing this up.

micahgodbolt avatar Jan 12 '18 21:01 micahgodbolt