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 input #582

Merged
merged 3 commits into from
Oct 19, 2024
Merged
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
62 changes: 37 additions & 25 deletions client/components/forms/CheckboxInput.vue
Original file line number Diff line number Diff line change
@@ -1,50 +1,63 @@
<template>
<input-wrapper v-bind="inputWrapperProps">
<InputWrapper v-bind="inputWrapperProps">
<template #label>
<span />
</template>

<v-checkbox
<div class="flex space-x-2 items-center">
<VCheckbox
:id="id ? id : name"
v-model="compVal"
:value="value"
:disabled="disabled ? true : null"
:name="name"
:color="color"
:theme="theme"
>
<slot
name="label"
>
<span
:class="[
theme.SelectInput.fontSize,
]"
>{{ label }}</span>
<span
v-if="required"
class="text-red-500 required-dot"
>*</span>
</slot>
</v-checkbox>
/>
<div>
<slot name="label">
<label
:aria-label="id ? id : name"
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Improve accessibility by using a descriptive 'aria-label'

The :aria-label attribute currently uses id ? id : name, which may not provide meaningful information to assistive technologies. It's recommended to use the label prop to ensure that screen readers convey the correct label to users.

Apply this diff to update the aria-label:

-            :aria-label="id ? id : name"
+            :aria-label="label"
📝 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
:aria-label="id ? id : name"
:aria-label="label"

:for="id ? id : name"
:class="theme.default.fontSize"
>
{{ label }}
<span
v-if="required"
class="text-red-500 required-dot"
>*</span>
</label>
</slot>
<slot name="help">
<InputHelp
:help="help"
:help-classes="theme.default.help"
>
<template #after-help>
<slot name="bottom_after_help" />
</template>
</InputHelp>
</slot>
</div>
</div>

<template #help>
<slot name="help" />
<span class="hidden" />
</template>

<template #error>
<slot name="error" />
</template>
</input-wrapper>
</InputWrapper>
</template>

<script>
import { inputProps, useFormInput } from "./useFormInput.js"
import VCheckbox from "./components/VCheckbox.vue"
import InputWrapper from "./components/InputWrapper.vue"
import { inputProps, useFormInput } from './useFormInput.js'
import VCheckbox from './components/VCheckbox.vue'
import InputWrapper from './components/InputWrapper.vue'

export default {
name: "CheckboxInput",
name: 'CheckboxInput',

components: { InputWrapper, VCheckbox },
props: {
Expand All @@ -59,9 +72,8 @@ export default {
},

mounted() {
if (!this.compVal) {
if (!this.compVal)
this.compVal = false
Comment on lines +75 to 76
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid initializing 'compVal' in the 'mounted' hook

Setting compVal in the mounted() hook can lead to reactivity issues and may not behave as expected during server-side rendering. It's better to initialize reactive properties within the data function or by setting a default value in the props.

Consider initializing compVal in the data method or via props:

Option 1: Initialize in data

export default {
  // ...
  data() {
    return {
      compVal: false,
    }
  },
  // ...
}

Option 2: Set a default prop value

props: {
  // ...
  compVal: { type: Boolean, default: false },
},

}
},
}
</script>
Loading