Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(useripple): fix inject warning #439

Merged
merged 1 commit into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/config-provider/useConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { computed, inject, reactive } from 'vue';
import { computed, inject } from 'vue';
import cloneDeep from 'lodash/cloneDeep';
import _mergeWith from 'lodash/mergeWith';
import { defaultGlobalConfig, GlobalConfig } from './context';
Expand Down
1 change: 0 additions & 1 deletion src/hooks/useKeepAnimation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { computed } from 'vue';
import { useConfig } from '../config-provider/useConfig';
import { EAnimationType } from '../config-provider/context';

Expand Down
19 changes: 11 additions & 8 deletions src/hooks/useRipple.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ref, onMounted, onUnmounted, Ref } from 'vue';
import useKeepAnimation from './useKeepAnimation';
import { usePrefixClass } from '../config-provider/useConfig';
import setStyle from '../utils/set-style';

const period = 200;
Expand Down Expand Up @@ -36,21 +35,25 @@ const getRippleColor = (el: HTMLElement, fixedRippleColor?: string) => {
*/
export default function useRipple(el: Ref<HTMLElement>, fixedRippleColor?: Ref<string>) {
const rippleContainer = ref(null);
const classPrefix = usePrefixClass();

// 全局配置ripple
const { keepRipple } = useKeepAnimation();

// 为节点添加斜八角动画 add ripple to the DOM and set up the animation
const handleAddRipple = (e: MouseEvent) => {
const dom = el.value;
const rippleColor = getRippleColor(dom, fixedRippleColor?.value);
if (e.button !== 0 || !el || !keepRipple) return;

if (
dom.classList.contains(`${classPrefix.value}-is-active`) ||
dom.classList.contains(`${classPrefix.value}-is-disabled`) ||
dom.classList.contains(`${classPrefix.value}-is-checked`)
)
return;
let isDisabled = false;
dom.classList.forEach((item) => {
// usePrefixClass 在此处是拿不到最新值的,usePrefixClass 依赖于useConfig, useConfig则依赖于inject,inject只在setUp和function component中生效
if (item.includes('-is-active') || item.includes('-is-disabled') || item.includes('-is-checked')) {
isDisabled = true;
}
});

if (isDisabled) return;

const elStyle = getComputedStyle(dom);

Expand Down