PagePathAutoComplete.jsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { pathUtils } from '@growi/core';
  4. import SearchTypeahead from './SearchTypeahead';
  5. const PagePathAutoComplete = (props) => {
  6. const {
  7. addTrailingSlash, initializedPath,
  8. } = props;
  9. function getKeywordOnInit(path) {
  10. if (path == null) {
  11. return;
  12. }
  13. return addTrailingSlash
  14. ? pathUtils.addTrailingSlash(path)
  15. : pathUtils.removeTrailingSlash(path);
  16. }
  17. return (
  18. <SearchTypeahead
  19. {...props}
  20. inputProps={{ name: 'new_path' }}
  21. placeholder="Input page path"
  22. keywordOnInit={getKeywordOnInit(initializedPath)}
  23. autoFocus={props.autoFocus}
  24. />
  25. );
  26. };
  27. PagePathAutoComplete.propTypes = {
  28. initializedPath: PropTypes.string,
  29. addTrailingSlash: PropTypes.bool,
  30. onChange: PropTypes.func,
  31. onSubmit: PropTypes.func,
  32. onInputChange: PropTypes.func,
  33. autoFocus: PropTypes.bool,
  34. };
  35. PagePathAutoComplete.defaultProps = {
  36. initializedPath: '/',
  37. autoFocus: false,
  38. };
  39. export default PagePathAutoComplete;