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(checkbox): modify mobile problem #2666

Merged
merged 1 commit into from
Dec 18, 2024
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
4 changes: 2 additions & 2 deletions examples/sites/demos/mobile/app/checkbox/checkbox-group.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<div class="checkbox-wrap">
<tiny-checkbox-group v-model="checked">
<tiny-checkbox label="复选框1"></tiny-checkbox>
<tiny-checkbox label="复选框2"></tiny-checkbox>
<tiny-checkbox label="复选框1">复选框1</tiny-checkbox>
<tiny-checkbox label="复选框2">复选框2</tiny-checkbox>
Comment on lines +4 to +5
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove duplicate label text to improve accessibility

The checkbox labels are currently specified both as a label prop and as child content, which could cause screen readers to announce the same text twice.

Apply this change to avoid duplication:

-      <tiny-checkbox label="复选框1">复选框1</tiny-checkbox>
-      <tiny-checkbox label="复选框2">复选框2</tiny-checkbox>
+      <tiny-checkbox label="复选框1" />
+      <tiny-checkbox label="复选框2" />

Or if you prefer using slot content:

-      <tiny-checkbox label="复选框1">复选框1</tiny-checkbox>
-      <tiny-checkbox label="复选框2">复选框2</tiny-checkbox>
+      <tiny-checkbox>复选框1</tiny-checkbox>
+      <tiny-checkbox>复选框2</tiny-checkbox>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<tiny-checkbox label="复选框1">复选框1</tiny-checkbox>
<tiny-checkbox label="复选框2">复选框2</tiny-checkbox>
<tiny-checkbox label="复选框1" />
<tiny-checkbox label="复选框2" />
Suggested change
<tiny-checkbox label="复选框1">复选框1</tiny-checkbox>
<tiny-checkbox label="复选框2">复选框2</tiny-checkbox>
<tiny-checkbox>复选框1</tiny-checkbox>
<tiny-checkbox>复选框2</tiny-checkbox>

</tiny-checkbox-group>
<p>当前选中的值为:{{ checked }}</p>
</div>
Expand Down
5 changes: 4 additions & 1 deletion packages/mobile/components/checkbox-group/src/mobile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@

<script lang="tsx">
import { renderless, api } from './renderless/vue'
import { setup, defineComponent } from '../../../vue-common'
import { $prefix, setup, defineComponent } from '../../../vue-common'
import Checkbox from '../../checkbox'
import { CheckboxGroupProps } from './checkbox-group'
import '@opentiny/vue-theme-mobile/checkbox-group/index.less'

export default defineComponent({
name: $prefix + 'CheckboxGroup',
componentName: 'CheckboxGroup',
components: {
Checkbox
},
props: CheckboxGroupProps,
emits: ['change', 'update:modelValue'],
setup(props, context) {
return setup({ props, context, renderless, api })
}
Expand Down
43 changes: 22 additions & 21 deletions packages/mobile/components/checkbox/src/checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,28 @@ import { $prefix } from '../../../vue-common'
import type { PropType } from '../../../vue-common'
import type { ExtractPropTypes, ComputedRef } from 'vue'
import type { ISharedRenderlessFunctionParams, ISharedRenderlessParamUtils } from '../../../types/shared.type'

import type {
addToStore,
removeFromStore,
computedStore,
computedFormItemSize,
computedIsChecked,
computedIsLimitDisabled,
computedIsDisabled,
computedIsDisplayOnly,
computedIsGroupDisplayOnly,
computedGetModelGet,
computedIsGroup,
computedCheckboxSize,
computedGetModelSet,
mounted,
handleChange,
computedDisplayLabel,
computedIsShowText,
computedShowText
} from './renderless'

export type { ISharedRenderlessParamHooks } from '../../../types/shared.type'

export type IconPosition = 'center' | 'top'
Expand Down Expand Up @@ -75,27 +97,6 @@ export const checkboxProps = {
}
}

import type {
addToStore,
removeFromStore,
computedStore,
computedFormItemSize,
computedIsChecked,
computedIsLimitDisabled,
computedIsDisabled,
computedIsDisplayOnly,
computedIsGroupDisplayOnly,
computedGetModelGet,
computedIsGroup,
computedCheckboxSize,
computedGetModelSet,
mounted,
handleChange,
computedDisplayLabel,
computedIsShowText,
computedShowText
} from './renderless'

export type ICheckboxSizeEnum = 'medium' | 'small' | 'mini'
export type ICheckboxModalValue = string | number | boolean

Expand Down
4 changes: 3 additions & 1 deletion packages/mobile/components/checkbox/src/mobile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@

<script lang="ts">
import { renderless, api } from './renderless/vue'
import { setup, defineComponent } from '../../../vue-common'
import { $prefix, setup, defineComponent } from '../../../vue-common'
import { checkboxProps } from './checkbox'
import '@opentiny/vue-theme-mobile/checkbox/index.less'

export default defineComponent({
name: $prefix + 'Checkbox',
componentName: 'Checkbox',
props: checkboxProps,
emits: ['update:modelValue', 'change', 'complete', 'click'],
setup(props, context) {
Expand Down
5 changes: 2 additions & 3 deletions packages/mobile/components/checkbox/src/renderless/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,9 @@ export const computedIsChecked =
}

export const computedIsGroup =
({ state, parent, constants }: Pick<ICheckboxRenderlessParams, 'state' | 'parent' | 'constants'>) =>
({ state, vm, constants }: Pick<ICheckboxRenderlessParams, 'state' | 'vm' | 'constants'>) =>
(): boolean => {
let parentObj = parent.$parent

let parentObj = vm.$parent
while (parentObj) {
if (parentObj.$options.componentName !== constants.CHECKBOX_GROUP) {
parentObj = parentObj.$parent
Expand Down
2 changes: 1 addition & 1 deletion packages/mobile/components/checkbox/src/renderless/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const initApi = ({
computedIsDisplayOnly: computedIsDisplayOnly({ state, props }),
computedIsGroupDisplayOnly: computedIsGroupDisplayOnly({ state }),
computedGetModelGet: computedGetModelGet({ state, props }),
computedIsGroup: computedIsGroup({ state, parent, constants }),
computedIsGroup: computedIsGroup({ state, vm, constants }),
computedCheckboxSize: computedCheckboxSize({ state, props, formItemSize }),
computedGetModelSet: computedGetModelSet({ state, dispatch, emit, constants }),
mounted: mounted({ emit, props, api, parent }),
Expand Down
Loading