简体   繁体   English

在Office UI Fabric React CommandBar中使用SearchBox

[英]Using the SearchBox in Office UI Fabric React CommandBar

I'm trying to work out how to use the built in search box component on the CommandBar within Office UI Fabric React 我正在尝试找出如何在Office UI Fabric React中使用CommandBar上的内置搜索框组件

The documentation at http://dev.office.com/fabric#/components/commandbar doesn't seem to cover it. http://dev.office.com/fabric#/components/commandbar上的文档似乎没有涵盖该文档。

Specifically I'd like to know how to get the search term entered and to execute a search 具体来说,我想知道如何输入搜索词并执行搜索

I've checked the source: https://github.com/OfficeDev/office-ui-fabric-react/blob/master/packages/office-ui-fabric-react/src/components/CommandBar/CommandBar.tsx 我检查了源代码: https : //github.com/OfficeDev/office-ui-fabric-react/blob/master/packages/office-ui-fabric-react/src/components/CommandBar/CommandBar.tsx

The searchbox is implemented as a simple input element: 搜索框被实现为一个简单的输入元素:

if (isSearchBoxVisible) {
  searchBox = (
    <div className={ css('ms-CommandBarSearch', styles.search) } ref='searchSurface'>
      <input className={ css('ms-CommandBarSearch-input', styles.searchInput) } type='text' placeholder={ searchPlaceholderText } />
      <div className={ css(
        'ms-CommandBarSearch-iconWrapper ms-CommandBarSearch-iconSearchWrapper',
        styles.searchIconWrapper, styles.searchIconSearchWrapper) }>
        <i className={ css('ms-Icon ms-Icon--Search') }></i>
      </div>
      <div className={ css(
        'ms-CommandBarSearch-iconWrapper ms-CommandBarSearch-iconClearWrapper ms-font-s',
        styles.searchIconWrapper,
        styles.searchIconClearWrapper
      ) }>
        <i className={ css('ms-Icon ms-Icon--Cancel') }></i>
      </div>
    </div>
  );
}

It can be accessed with the refs property: 可以使用refs属性访问它:

  public refs: {
    [key: string]: React.ReactInstance;
    commandSurface: HTMLElement;
    farCommandSurface: HTMLElement;
    commandBarRegion: HTMLElement;
    searchSurface: HTMLElement;
    focusZone: FocusZone;
  };

Now you could try to use the standard properties and events of an input element. 现在,您可以尝试使用输入元素的标准属性和事件。 (I haven't tried.) (我没有尝试过。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM