Repository navigation
fix: style #7774
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: style #7774
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,7 @@ defineExpose({ handleOpen, handleClose }) | |
| v-if="!hideWhenEmpty || hasDropdownContent(slots.dropdown?.())" | ||
| class="mk-dropdown" | ||
| ref="dropdownRef" | ||
| :popper-options="popperOptions" | ||
| :persistent="persistent && hasOpened" | ||
| v-bind="$attrs" | ||
| @visible-change="handleVisibleChange" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is an analysis of the code snippet: 1. Potential Issues & Irregularities
2. Optimization Suggestions
Example Fix (Vue 3 Composition API Script):<script setup lang="ts">
import { ref } from 'vue';
// Define popper options correctly
const popperOptions = ref({
modifiers: [
{ name: 'offset', options: { offset: [0, 8] } }
],
});
</script> |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| import { computed } from 'vue' | ||
| import type { CSSProperties } from 'vue' | ||
| import type { ApplicationDisplaySetting } from '@/api/types' | ||
| import defaultFloatIconUrl from '/MaxKB.gif?url' | ||
|
|
||
| defineOptions({ name: 'DisplaySettingPreview' }) | ||
|
|
||
|
|
@@ -79,6 +80,6 @@ const previewHeaderStyle = computed<CSSProperties>(() => ({ | |
| </div> | ||
| </div> | ||
| <!-- 浮窗图标 --> | ||
| <img :src="previewImages.float_icon || './MaxKB.gif'" alt="" class="size-8 shrink-0 object-contain" /> | ||
| <img :src="previewImages.float_icon || defaultFloatIconUrl" alt="" class="size-8 shrink-0 object-contain" /> | ||
| </div> | ||
| </template> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Analysis & Suggestions1. Naming Convention Inconsistency (Potential Issue)
2. Missing Null/Empty String Check (Optimization/Safety)
3. Alt Text Accessibility (Best Practice)
4. Import Path Portability (Minor Suggestion)
Summary of Recommended ChangeThe change from a hardcoded string to an imported module is good practice. It ensures the asset is resolved by the build tool and benefits from hashing/cache-busting. No critical bugs detected. Just verify the file path resolves correctly in your build environment.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is an analysis of the code changes: 1. Import Path Issue (Potential Bug)Irregularity: If import defaultFloatIconUrl from '@/assets/MaxKB.gif?url' // or appropriate relative/path alias2. Hardcoded Path in ImportSuggestion: While functional, hardcoding the filename directly in the import statement ( 3. Vue Reactivity & Optimization (No Change Needed, but Good Practice)
4. Alt AttributeMinor Observation: The ✅ Recommended Fix (if path is incorrect)Assuming - import defaultFloatIconUrl from '/MaxKB.gif?url'
+ import defaultFloatIconUrl from '@/assets/images/MaxKB.gif?url' // Adjust path based on actual locationIf it is in the const defaultFloatIconUrl = '/MaxKB.gif'; // No import needed, use string directly or define constBut since you're using |
||
| Original file line number | Diff line number | Diff line change | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -85,6 +85,7 @@ function handleRefresh() { | ||||||||||||||||
| placement="bottom-end" | |||||||||||||||||
| persistent | |||||||||||||||||
| :class="{ 'w-full': $slots.trigger }" | |||||||||||||||||
| :popper-options="fitTriggerWidth ? { modifiers: [{ name: 'computeStyles', options: { roundOffsets: false } }] } : undefined" | |||||||||||||||||
| :popper-style="dropdownStyle" | |||||||||||||||||
| :popper-class="popperClass" | |||||||||||||||||
| @visible-change="handleVisibleChange" | |||||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is an analysis of the code snippet, focusing on irregularities, potential issues, and optimization suggestions. Potential Issues & Irregularities
Optimization Suggestions✅ Recommended Refactor (Using Computed Property)Move the logic out of the template to avoid creating new objects on every render and to improve readability. In // Example using Composition API (setup)
const popperOptions = computed(() => {
// Base options from props or defaults
const baseOptions = props.basePopperOptions || {};
if (props.fitTriggerWidth) {
return {
...baseOptions,
modifiers: [
...(baseOptions.modifiers || []),
{
name: 'computeStyles',
options: {
roundOffsets: false
}
}
]
};
}
return baseOptions;
});In Template: <popper
:popper-options="popperOptions"
:popper-style="dropdownStyle"
:popper-class="popperClass"
@visible-change="handleVisibleChange"
/>Summary of Actions
Final NoteIf
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here are the key issues and suggestions for the provided code snippet: 1. Invalid JavaScript Object SyntaxThe value assigned to Current: { modifiers: [{ name: 'computeStyles', options: { roundOffsets: false } }] }Note: While this looks syntactically correct as an object literal, Actually, in Popper.js v2, there is no 2. Performance & MaintainabilityInlining complex configuration objects directly in the template can lead to:
3. Suggested Improvement✅ Extract to a Computed PropertyMove the logic out of the template for clarity and potential caching (though Vue may optimize it, explicit control is better): <script setup>
// ...
const fitTriggerWidth = ref(false) // example state
const popperOptions = computed(() =>
fitTriggerWidth.value
? {
modifiers: [
{
name: 'computeStyles',
options: {
gpuAcceleration: false, // Common way to reduce layout shift/jumpiness
},
},
],
}
: undefined
)
</script>
<template>
<component
:popper-options="popperOptions"
:popper-style="dropdownStyle"
:popper-class="popperClass"
@visible-change="handleVisibleChange"
/>
</template>✅ Fix Popper Options (If Using Vuetify/Nuxt UI)If you're trying to ensure the dropdown matches trigger width, many libraries (like Nuxt UI) provide built-in props (e.g., Summary of Actions:
|
|||||||||||||||||
|
|
|||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a concise review:
slots.dropdown?.()): Callingslots.dropdownduring template rendering causes unnecessary re-evaluation on every parent update. Use<slot name="dropdown" />in the template instead, or computehasDropdownContentvia a watcher/computed property that checks slot existence/length without invoking functions directly inv-if conditionals if avoidable.refbefore props (popper-options) is fine, but ensurepopperOptionsis defined and reactive in the script setup to benefit from Vue 3’s automatic unwrapping.hasDropdownContentis expensive, memoize it or usecomputed. Avoid passing$attrsunless necessary to prevent prop leakage.