fix: add useRef hook
parent
2b78d2dbc0
commit
7ec594c5fc
|
@ -0,0 +1,14 @@
|
||||||
|
import { onBeforeUpdate, readonly, ref, DeepReadonly, UnwrapRef } from 'vue';
|
||||||
|
|
||||||
|
export type UseRef = [(el: any) => void, DeepReadonly<UnwrapRef<any[]>>];
|
||||||
|
|
||||||
|
export const useRef = (): UseRef => {
|
||||||
|
const refs = ref<any>([]);
|
||||||
|
const setRef = (el: any) => {
|
||||||
|
refs.value.push(el);
|
||||||
|
};
|
||||||
|
onBeforeUpdate(() => {
|
||||||
|
refs.value = [];
|
||||||
|
});
|
||||||
|
return [setRef, readonly(refs)];
|
||||||
|
};
|
|
@ -19,6 +19,7 @@ import Tooltip from '../tooltip';
|
||||||
import useConfigInject from '../_util/hooks/useConfigInject';
|
import useConfigInject from '../_util/hooks/useConfigInject';
|
||||||
|
|
||||||
import Star from './Star';
|
import Star from './Star';
|
||||||
|
import { useRef } from '../_util/hooks/useRef';
|
||||||
|
|
||||||
export const rateProps = {
|
export const rateProps = {
|
||||||
prefixCls: PropTypes.string,
|
prefixCls: PropTypes.string,
|
||||||
|
@ -52,22 +53,16 @@ const Rate = defineComponent({
|
||||||
setup(props, { slots, attrs, emit, expose }) {
|
setup(props, { slots, attrs, emit, expose }) {
|
||||||
const { prefixCls, direction } = useConfigInject('rate', props);
|
const { prefixCls, direction } = useConfigInject('rate', props);
|
||||||
const rateRef = ref();
|
const rateRef = ref();
|
||||||
const starRefs = ref([]);
|
const [setRef, starRefs] = useRef();
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
sValue: props.value,
|
sValue: props.value,
|
||||||
focused: false,
|
focused: false,
|
||||||
cleanedValue: null,
|
cleanedValue: null,
|
||||||
hoverValue: undefined,
|
hoverValue: undefined,
|
||||||
});
|
});
|
||||||
const saveRef = (el: any) => {
|
|
||||||
starRefs.value.push(el);
|
|
||||||
};
|
|
||||||
onBeforeUpdate(() => {
|
|
||||||
starRefs.value = [];
|
|
||||||
});
|
|
||||||
|
|
||||||
const getStarDOM = index => {
|
const getStarDOM = index => {
|
||||||
return findDOMNode(starRefs.value[index]);
|
return findDOMNode(starRefs[index]);
|
||||||
};
|
};
|
||||||
const getStarValue = (index, x) => {
|
const getStarValue = (index, x) => {
|
||||||
const reverse = direction.value === 'rtl';
|
const reverse = direction.value === 'rtl';
|
||||||
|
@ -200,7 +195,7 @@ const Rate = defineComponent({
|
||||||
for (let index = 0; index < count; index++) {
|
for (let index = 0; index < count; index++) {
|
||||||
stars.push(
|
stars.push(
|
||||||
<Star
|
<Star
|
||||||
ref={saveRef}
|
ref={setRef}
|
||||||
key={index}
|
key={index}
|
||||||
index={index}
|
index={index}
|
||||||
count={count}
|
count={count}
|
||||||
|
|
2
v2-doc
2
v2-doc
|
@ -1 +1 @@
|
||||||
Subproject commit 0f6d531d088d5283250c8cec1c7e8be0e0d36a36
|
Subproject commit 4f1ece5073f736e79c6eb22527a9a83e8c6182b3
|
Loading…
Reference in New Issue