import getMatchBounds from './getMatchBounds' ; import getOptionLabel from './getOptionLabel' ; import hasOwnProperty from './hasOwnProperty' ; import { isString } from './nodash' ; import { LabelKey , Option } from '../types' ; interface HintProps { activeIndex : number ; initialItem ? : Option ; isFocused : boolean ; isMenuShown : boolean ; labelKey : LabelKey ; multiple : boolean ; selected : Option [ ] ; text : string ; } function getHintText ( { activeIndex , initialItem , isFocused , isMenuShown , labelKey , multiple , selected , text , } ) { if ( ! text || ! isFocused || ! isMenuShown || ! initialItem || ( ! isString ( initialItem ) && hasOwnProperty ( initialItem , 'customOption' ) ) || activeIndex > - 1 || ( ! ! selected . length && ! multiple ) ) { return '' ; } const initialItemStr = getOptionLabel ( initialItem , labelKey ) ; const bounds = getMatchBounds ( initialItemStr . toLowerCase ( ) , text . toLowerCase ( ) ) ; if ( ! ( bounds && bounds . start === 0 ) ) { return '' ; } return text + initialItemStr . slice ( bounds . end , initialItemStr . length ) ; } export default getHintText ;