useActive.js 756 B

12345678910111213141516171819202122232425
  1. import { useInjectCascader } from '../context';
  2. import { watch } from 'vue';
  3. import { useBaseProps } from '../../vc-select';
  4. import useState from '../../_util/hooks/useState';
  5. /**
  6. * Control the active open options path.
  7. */
  8. export default (() => {
  9. const baseProps = useBaseProps();
  10. const {
  11. values
  12. } = useInjectCascader();
  13. // Record current dropdown active options
  14. // This also control the open status
  15. const [activeValueCells, setActiveValueCells] = useState([]);
  16. watch(() => baseProps.open, () => {
  17. if (baseProps.open && !baseProps.multiple) {
  18. const firstValueCells = values.value[0];
  19. setActiveValueCells(firstValueCells || []);
  20. }
  21. }, {
  22. immediate: true
  23. });
  24. return [activeValueCells, setActiveValueCells];
  25. });