You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
683 B
31 lines
683 B
import { ref } from 'vue';
|
|
import canUseDom from '../../_util/canUseDom';
|
|
|
|
let uuid = 0;
|
|
|
|
/** Is client side and not jsdom */
|
|
export const isBrowserClient = process.env.NODE_ENV !== 'test' && canUseDom();
|
|
|
|
/** Get unique id for accessibility usage */
|
|
export function getUUID(): number | string {
|
|
let retId: string | number;
|
|
|
|
// Test never reach
|
|
/* istanbul ignore if */
|
|
if (isBrowserClient) {
|
|
retId = uuid;
|
|
uuid += 1;
|
|
} else {
|
|
retId = 'TEST_OR_SSR';
|
|
}
|
|
|
|
return retId;
|
|
}
|
|
|
|
export default function useId(id = ref('')) {
|
|
// Inner id for accessibility usage. Only work in client side
|
|
const innerId = `rc_select_${getUUID()}`;
|
|
|
|
return id.value || innerId;
|
|
}
|