import classnames from 'classnames'; import raf from 'raf'; import {defineComponent, getCurrentInstance, nextTick, onMounted, ref, watch} from 'vue'; import PropTypes from '../_util/vue-types'; function noop() { } const scrollTo = (element, to, duration) => { // jump to target if duration zero if (duration <= 0) { raf(() => { element.scrollTop = to; }); return; } const difference = to - element.scrollTop; const perTick = (difference / duration) * 10; raf(() => { element.scrollTop += perTick; if (element.scrollTop === to) { return; } scrollTo(element, to, duration - 10); }); }; const Select = defineComponent({ props: { prefixCls: PropTypes.string, options: PropTypes.array, selectedIndex: PropTypes.number, type: PropTypes.string // onSelect: PropTypes.func, // onMouseEnter: PropTypes.func, }, setup(props, {emit}) { const active = ref(false); const instance = getCurrentInstance(); const listRef = ref(undefined); const onSelect = (value) => { const {type} = props; emit('select', type, value); }; const onEsc = (e) => { emit('esc', e); }; const getOptions = () => { const {options, selectedIndex, prefixCls} = props; return options.map((item, index) => { const cls = classnames({ [`${prefixCls}-select-option-selected`]: selectedIndex === index, [`${prefixCls}-select-option-disabled`]: item.disabled }); const onClick = item.disabled ? noop : () => { onSelect(item.value); }; const onKeyDown = e => { if (e.key === 'Enter') { onClick(); } else if (e.key === 'Escape') { onEsc(e); } }; return (