Skip to content

Commit 50b83bc

Browse files
committed
fix(radio): add ripple effect on text click
1 parent 077bb9d commit 50b83bc

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

packages/varlet-ui/src/radio/Radio.vue

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<div :class="n('wrap')">
33
<div
44
ref="action"
5+
v-hover:desktop="handleHovering"
56
role="radio"
67
:tabindex="tabIndex"
78
:aria-checked="checked"
@@ -13,8 +14,8 @@
1314
@blur="isFocusing = false"
1415
>
1516
<div
17+
ref="circleRef"
1618
v-ripple="{ disabled: formReadonly || readonly || formDisabled || disabled || !ripple }"
17-
v-hover:desktop="handleHovering"
1819
:class="
1920
classes(
2021
n('action'),
@@ -64,7 +65,7 @@ import { useForm } from '../form/provide'
6465
import Hover from '../hover'
6566
import VarHoverOverlay, { useHoverOverlay } from '../hover-overlay'
6667
import VarIcon from '../icon'
67-
import Ripple from '../ripple'
68+
import Ripple, { RippleHTMLElement } from '../ripple'
6869
import { createNamespace, useValidation } from '../utils/components'
6970
import { props, type RadioValidateTrigger } from './props'
7071
import { useRadioGroup, type RadioProvider } from './provide'
@@ -83,6 +84,7 @@ export default defineComponent({
8384
props,
8485
setup(props) {
8586
const action = ref<HTMLElement>()
87+
const circleRef = ref<RippleHTMLElement>()
8688
const isFocusing = ref(false)
8789
const value = useVModel(props, 'modelValue')
8890
const checked = computed(() => value.value === props.checkedValue)
@@ -200,6 +202,19 @@ export default defineComponent({
200202
}
201203
202204
function handleTextClick() {
205+
// Manually trigger the ripple effect on text click
206+
if (circleRef.value) {
207+
if (circleRef.value?._ripple && typeof circleRef.value?._ripple?.removeRipple === 'function') {
208+
// Remove any existing ripple
209+
circleRef.value._ripple?.removeRipple()
210+
}
211+
212+
if (circleRef.value?._ripple && typeof circleRef.value?.dispatchEvent === 'function') {
213+
// Create a fake keyboard event to trigger the ripple
214+
const event = new Event('touchstart')
215+
circleRef.value.dispatchEvent(event)
216+
}
217+
}
203218
action.value!.focus()
204219
}
205220
@@ -236,6 +251,7 @@ export default defineComponent({
236251
237252
return {
238253
action,
254+
circleRef,
239255
isFocusing,
240256
checked,
241257
errorMessage,

packages/varlet-ui/src/ripple/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ interface RippleOptions {
2222
tasker?: number | null
2323
}
2424

25-
interface RippleHTMLElement extends HTMLElement {
25+
export interface RippleHTMLElement extends HTMLElement {
2626
_ripple?: RippleOptions
2727
}
2828

0 commit comments

Comments
 (0)