diff --git a/common/changes/office-ui-fabric-react/searchbox-anim-prop_2018-05-07-16-13.json b/common/changes/office-ui-fabric-react/searchbox-anim-prop_2018-05-07-16-13.json new file mode 100644 index 0000000000000..50cf3226419f3 --- /dev/null +++ b/common/changes/office-ui-fabric-react/searchbox-anim-prop_2018-05-07-16-13.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "office-ui-fabric-react", + "comment": "SearchBox: New prop for turning off icon animation.", + "type": "minor" + } + ], + "packageName": "office-ui-fabric-react", + "email": "lynam.emily@gmail.com" +} \ No newline at end of file diff --git a/packages/office-ui-fabric-react/src/components/SearchBox/SearchBox.base.tsx b/packages/office-ui-fabric-react/src/components/SearchBox/SearchBox.base.tsx index c25b89b947aa8..2f826465dcfcf 100644 --- a/packages/office-ui-fabric-react/src/components/SearchBox/SearchBox.base.tsx +++ b/packages/office-ui-fabric-react/src/components/SearchBox/SearchBox.base.tsx @@ -22,6 +22,10 @@ export interface ISearchBoxState { @customizable('SearchBox', ['theme']) export class SearchBoxBase extends BaseComponent { + public static defaultProps: ISearchBoxProps = { + disableAnimation: false + }; + private _rootElement = createRef(); private _inputElement = createRef(); private _latestValue: string; @@ -62,7 +66,8 @@ export class SearchBoxBase extends BaseComponent 0 + hasInput: value!.length > 0, + disableAnimation }); return ( diff --git a/packages/office-ui-fabric-react/src/components/SearchBox/SearchBox.styles.tsx b/packages/office-ui-fabric-react/src/components/SearchBox/SearchBox.styles.tsx index 11564d48c9c87..f0b67aa48d5b5 100644 --- a/packages/office-ui-fabric-react/src/components/SearchBox/SearchBox.styles.tsx +++ b/packages/office-ui-fabric-react/src/components/SearchBox/SearchBox.styles.tsx @@ -6,7 +6,7 @@ import { import { ISearchBoxStyleProps, ISearchBoxStyles } from './SearchBox.types'; export function getStyles(props: ISearchBoxStyleProps): ISearchBoxStyles { - const { theme, underlined, disabled, hasFocus, className, hasInput } = props; + const { theme, underlined, disabled, hasFocus, className, hasInput, disableAnimation } = props; const { palette, fonts, semanticColors } = theme; return { @@ -88,27 +88,29 @@ export function getStyles(props: ISearchBoxStyleProps): ISearchBoxStyles { fontSize: 16, width: 32, textAlign: 'center', - transition: `width ${AnimationVariables.durationValue1}`, color: palette.themePrimary, cursor: 'text' }, hasFocus && { - width: 4, - transition: `width ${AnimationVariables.durationValue1}` + width: 4 }, disabled && { color: palette.neutralTertiary + }, + !disableAnimation && { + transition: `width ${AnimationVariables.durationValue1}` } ], icon: [ 'ms-SearchBox-icon', { opacity: 1, - transition: `opacity ${AnimationVariables.durationValue1} 0s` }, hasFocus && { - opacity: 0, - transition: `opacity 0 ${AnimationVariables.durationValue1}` + opacity: 0 + }, + !disableAnimation && { + transition: `opacity ${AnimationVariables.durationValue1} 0s` } ], clearButton: [ diff --git a/packages/office-ui-fabric-react/src/components/SearchBox/SearchBox.test.tsx b/packages/office-ui-fabric-react/src/components/SearchBox/SearchBox.test.tsx index e3ceb42150d54..f52236a1c0749 100644 --- a/packages/office-ui-fabric-react/src/components/SearchBox/SearchBox.test.tsx +++ b/packages/office-ui-fabric-react/src/components/SearchBox/SearchBox.test.tsx @@ -35,4 +35,10 @@ describe('SearchBox', () => { expect(component.find('input').prop('value')).toEqual(''); }); + + it('renders SearchBox without animation correctly', () => { + const component = renderer.create(); + const tree = component.toJSON(); + expect(tree).toMatchSnapshot(); + }); }); \ No newline at end of file diff --git a/packages/office-ui-fabric-react/src/components/SearchBox/SearchBox.types.ts b/packages/office-ui-fabric-react/src/components/SearchBox/SearchBox.types.ts index 0140d37b85b2a..2194f684855fd 100644 --- a/packages/office-ui-fabric-react/src/components/SearchBox/SearchBox.types.ts +++ b/packages/office-ui-fabric-react/src/components/SearchBox/SearchBox.types.ts @@ -103,6 +103,12 @@ export interface ISearchBoxProps extends React.InputHTMLAttributes; + + /** + * Whether or not to animate the SearchBox icon on focus. + * @default false + */ + disableAnimation?: boolean; } export interface ISearchBoxStyleProps { @@ -112,6 +118,7 @@ export interface ISearchBoxStyleProps { hasFocus?: boolean; underlined?: boolean; hasInput?: boolean; + disableAnimation?: boolean; } export interface ISearchBoxStyles { diff --git a/packages/office-ui-fabric-react/src/components/SearchBox/__snapshots__/SearchBox.test.tsx.snap b/packages/office-ui-fabric-react/src/components/SearchBox/__snapshots__/SearchBox.test.tsx.snap index 50badea70adea..b8b036aef0a76 100644 --- a/packages/office-ui-fabric-react/src/components/SearchBox/__snapshots__/SearchBox.test.tsx.snap +++ b/packages/office-ui-fabric-react/src/components/SearchBox/__snapshots__/SearchBox.test.tsx.snap @@ -126,3 +126,128 @@ exports[`SearchBox renders SearchBox correctly 1`] = ` /> `; + +exports[`SearchBox renders SearchBox without animation correctly 1`] = ` +
+
+ +  + +
+ +
+`; diff --git a/packages/office-ui-fabric-react/src/components/SearchBox/examples/SearchBox.FullSize.Example.tsx b/packages/office-ui-fabric-react/src/components/SearchBox/examples/SearchBox.FullSize.Example.tsx index c429e96a492bf..a08a671c82ddd 100644 --- a/packages/office-ui-fabric-react/src/components/SearchBox/examples/SearchBox.FullSize.Example.tsx +++ b/packages/office-ui-fabric-react/src/components/SearchBox/examples/SearchBox.FullSize.Example.tsx @@ -1,17 +1,27 @@ import * as React from 'react'; import { SearchBox } from 'office-ui-fabric-react/lib/SearchBox'; +import './SearchBox.Examples.scss'; // tslint:disable:jsx-no-lambda export class SearchBoxFullSizeExample extends React.Component { public render(): JSX.Element { return ( - console.log('onFocus called') } - onBlur={ () => console.log('onBlur called') } - onChange={ () => console.log('onChange called') } - /> +
+ console.log('onFocus called') } + onBlur={ () => console.log('onBlur called') } + onChange={ () => console.log('onChange called') } + /> + console.log('onFocus called') } + onBlur={ () => console.log('onBlur called') } + onChange={ () => console.log('onChange called') } + disableAnimation + /> +
); }