Skip to content

Commit

Permalink
Revert "fix(components): [radio] Divide attrs into label and input (#…
Browse files Browse the repository at this point in the history
…8476)"

This reverts commit 2d8a9e4.
  • Loading branch information
chenxch committed Jul 6, 2022
1 parent ec34126 commit 1e44f35
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 68 deletions.
50 changes: 0 additions & 50 deletions packages/components/radio/__tests__/radio.test.tsx
Expand Up @@ -373,54 +373,4 @@ describe('Radio Button', () => {
expect(radioGroup2.attributes()['aria-labelledby']).toBeFalsy()
})
})

describe('laebl for', () => {
test('label and radio', async () => {
const radio = ref('')
const forId = ref('radio1121')
const wrapper = mount(() => (
<>
<label for={forId.value}>click here</label>
<Radio v-model={radio.value} label="Foo" id="radio1121" />
</>
))
await nextTick()
const label = wrapper.find('label')
label.trigger('click')
expect(radio.value).toBe('Foo')
// no for
radio.value = ''
forId.value = undefined
await nextTick()
label.trigger('click')
expect(radio.value).toBe('')
})

test('label and radioGroup', async () => {
const compList = [Radio]
compList.forEach(async (comp) => {
const radio = ref('')
const forId = ref('radio1121')
const wrapper = mount(() => (
<>
<label for={forId.value}>click here</label>
<RadioGroup v-model={radio.value}>
<comp label="Foo" id="radio1121" />
<comp label="Bar" id="radio1122" />
</RadioGroup>
</>
))
await nextTick()
const label = wrapper.find('label')
label.trigger('click')
expect(radio.value).toBe('Foo')
// no for
radio.value = ''
forId.value = undefined
await nextTick()
label.trigger('click')
expect(radio.value).toBe('')
})
})
})
})
20 changes: 2 additions & 18 deletions packages/components/radio/src/radio.vue
Expand Up @@ -7,10 +7,7 @@
ns.is('bordered', border),
ns.is('checked', modelValue === label),
ns.m(size),
rawAttrs.class,
]"
:style="containerStyle"
v-bind="labelListieners"
>
<span
:class="[
Expand All @@ -27,7 +24,6 @@
:name="name || radioGroup?.name"
:disabled="disabled"
type="radio"
v-bind="inputAttrs"
@focus="focus = true"
@blur="focus = false"
@change="handleChange"
Expand All @@ -43,29 +39,17 @@
</template>
<script lang="ts" setup>
import { computed, nextTick, useAttrs as useRawAttrs } from 'vue'
import { useAttrs, useNamespace } from '@element-plus/hooks'
import { nextTick } from 'vue'
import { useNamespace } from '@element-plus/hooks'
import { radioEmits, radioProps } from './radio'
import { useRadio } from './use-radio'
import type { StyleValue } from 'vue'
defineOptions({
name: 'ElRadio',
inheritAttrs: false,
})
const props = defineProps(radioProps)
const emit = defineEmits(radioEmits)
const rawAttrs = useRawAttrs()
const containerStyle = computed<StyleValue>(() => rawAttrs.style as StyleValue)
const inputAttrs = useAttrs({ excludeListeners: true })
const labelListieners = useAttrs({
excludeKeys: computed<string[]>(() => {
return Object.keys(inputAttrs.value)
}),
})
const ns = useNamespace('radio')
const { radioRef, radioGroup, focus, size, disabled, modelValue } = useRadio(
Expand Down

0 comments on commit 1e44f35

Please sign in to comment.