-
Notifications
You must be signed in to change notification settings - Fork 278
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
feat(autocomplete): [autocomplete] update autocomplete demos #2384
Conversation
WalkthroughThe changes in this pull request involve updates to the Changes
Possibly related PRs
Suggested labels
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 6
🧹 Outside diff range and nitpick comments (3)
examples/sites/demos/pc/app/autocomplete/size.spec.ts (1)
12-15
: Consider adding more comprehensive test coverage.While the height assertions are good, consider adding tests to verify:
- The input fields are actually rendered and visible
- The autocomplete functionality works correctly for each size variant
- The dropdown positioning is correct for each size
Example additional assertions:
// Verify input fields are visible await expect(mediumSize.locator('input')).toBeVisible() // Verify dropdown positioning await mediumSize.locator('input').click() await expect(mediumSize.locator('.tiny-autocomplete__dropdown')).toBeVisible()examples/sites/demos/pc/app/autocomplete/size-composition-api.vue (1)
5-10
: Consider adding ARIA labels for better accessibility.The autocomplete components could benefit from proper ARIA labels to improve accessibility. Consider adding
aria-label
attributes that describe the size of each autocomplete.<tiny-autocomplete size="medium" v-model="value" :fetch-suggestions="querySearch" placeholder="请输入内容" + aria-label="Medium sized autocomplete" ></tiny-autocomplete>
Also applies to: 14-14, 18-23, 27-32
examples/sites/demos/pc/app/autocomplete/size.vue (1)
3-33
: Consider improving accessibilityThe autocomplete demos could benefit from improved accessibility:
- Add aria-label to each autocomplete instance
- Ensure sufficient color contrast for title text
Example improvement:
- <tiny-autocomplete + <tiny-autocomplete + :aria-label="`${size} size autocomplete demo`" :size="size" v-model="value" :fetch-suggestions="querySearch" placeholder="请输入内容" ></tiny-autocomplete>
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (4)
- examples/sites/demos/pc/app/autocomplete/size-composition-api.vue (2 hunks)
- examples/sites/demos/pc/app/autocomplete/size.spec.ts (1 hunks)
- examples/sites/demos/pc/app/autocomplete/size.vue (2 hunks)
- examples/sites/demos/pc/app/autocomplete/webdoc/autocomplete.js (1 hunks)
🔇 Additional comments (4)
examples/sites/demos/pc/app/autocomplete/size-composition-api.vue (2)
93-98
: LGTM! Well-structured CSS.The added styles provide consistent spacing and alignment. The selectors are properly scoped and follow good CSS practices.
7-7
: Verify the shared v-model behavior.All autocomplete instances are bound to the same
value
model. This means changing one autocomplete will affect all others. Consider using separate v-models if independent values are needed.Also applies to: 14-14, 20-20, 29-29
examples/sites/demos/pc/app/autocomplete/size.vue (1)
100-105
: LGTM! CSS changes improve layout and readabilityThe added styles provide appropriate spacing and alignment for the demo layout.
examples/sites/demos/pc/app/autocomplete/webdoc/autocomplete.js (1)
32-32
: LGTM! Name change improves consistency.The simplified Chinese name '尺寸' better aligns with the component's documentation style.
await page.getByRole('option', { name: 'WWWW科技YX公司' }).click() | ||
await expect(page.locator('//div[@class="tiny-input tiny-input-medium"]')).toHaveClass(/tiny-input-medium/) | ||
const demo = page.locator('#size') | ||
const meiumSize = demo.locator('.tiny-autocomplete').first() |
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.
Fix typo in variable name: "meiumSize" should be "mediumSize".
The variable name contains a spelling error.
- const meiumSize = demo.locator('.tiny-autocomplete').first()
+ const mediumSize = demo.locator('.tiny-autocomplete').first()
📝 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.
const meiumSize = demo.locator('.tiny-autocomplete').first() | |
const mediumSize = demo.locator('.tiny-autocomplete').first() |
const meiumSize = demo.locator('.tiny-autocomplete').first() | ||
const defaultSize = demo.locator('.tiny-autocomplete').nth(1) | ||
const smallSize = demo.locator('.tiny-autocomplete').nth(2) | ||
const miniSize = demo.locator('.tiny-autocomplete').nth(3) |
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.
🛠️ Refactor suggestion
Use more robust selectors instead of order-dependent ones.
The current selectors rely on element order which can be fragile if the DOM structure changes. Consider using more specific selectors based on data attributes or size classes.
- const meiumSize = demo.locator('.tiny-autocomplete').first()
- const defaultSize = demo.locator('.tiny-autocomplete').nth(1)
- const smallSize = demo.locator('.tiny-autocomplete').nth(2)
- const miniSize = demo.locator('.tiny-autocomplete').nth(3)
+ const mediumSize = demo.locator('[data-size="medium"]')
+ const defaultSize = demo.locator('[data-size="default"]')
+ const smallSize = demo.locator('[data-size="small"]')
+ const miniSize = demo.locator('[data-size="mini"]')
Committable suggestion was skipped due to low confidence.
></tiny-autocomplete> | ||
</div> | ||
<div> | ||
<div class="title">small:</div> |
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.
Fix incorrect title text for mini size.
The title text shows "small:" for the mini-sized autocomplete component.
- <div class="title">small:</div>
+ <div class="title">mini:</div>
📝 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.
<div class="title">small:</div> | |
<div class="title">mini:</div> |
<div> | ||
<div class="title">medium:</div> | ||
<tiny-autocomplete | ||
size="medium" | ||
v-model="value" | ||
:fetch-suggestions="querySearch" | ||
placeholder="请输入内容" | ||
></tiny-autocomplete> | ||
</div> | ||
<div> | ||
<div class="title">default:</div> | ||
<tiny-autocomplete v-model="value" :fetch-suggestions="querySearch" placeholder="请输入内容"></tiny-autocomplete> | ||
</div> | ||
<div> | ||
<div class="title">small:</div> | ||
<tiny-autocomplete | ||
size="small" | ||
v-model="value" | ||
:fetch-suggestions="querySearch" | ||
placeholder="请输入内容" | ||
></tiny-autocomplete> | ||
</div> | ||
<div> | ||
<div class="title">small:</div> | ||
<tiny-autocomplete | ||
size="mini" | ||
v-model="value" | ||
:fetch-suggestions="querySearch" | ||
placeholder="请输入内容" | ||
></tiny-autocomplete> | ||
</div> |
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.
🛠️ Refactor suggestion
Consider refactoring repeated component structure
The current implementation has significant code duplication. Consider refactoring using a v-for loop with a configuration array.
<template>
<div class="demo-autocomplete">
- <div>
- <div class="title">medium:</div>
- <tiny-autocomplete
- size="medium"
- v-model="value"
- :fetch-suggestions="querySearch"
- placeholder="请输入内容"
- ></tiny-autocomplete>
- </div>
- <!-- ... other repeated blocks ... -->
+ <div v-for="size in sizes" :key="size">
+ <div class="title">{{ size }}:</div>
+ <tiny-autocomplete
+ :size="size === 'default' ? undefined : size"
+ v-model="value"
+ :fetch-suggestions="querySearch"
+ placeholder="请输入内容"
+ ></tiny-autocomplete>
+ </div>
</div>
</template>
Add to the data section:
data() {
return {
restaurants: [],
value: '',
sizes: ['medium', 'default', 'small', 'mini']
}
}
></tiny-autocomplete> | ||
</div> | ||
<div> | ||
<div class="title">small:</div> |
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.
Fix incorrect title text for mini size variant
The title shows "small:" but this section demonstrates the "mini" size variant.
- <div class="title">small:</div>
+ <div class="title">mini:</div>
📝 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.
<div class="title">small:</div> | |
<div class="title">mini:</div> |
'zh-CN': | ||
'<p>可选择值为<code>medium</code>,<code>default</code>,<code>small</code>,<code>mini</code>,不传递就是默认尺寸。</p>', | ||
'en-US': '<p>The value can be <code>medium</code>, <code>small</code>, or <code>mini</code>.</p>' |
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.
Update English description to match Chinese changes.
The Chinese description has been updated to include all size options (medium
, default
, small
, mini
) and clarifies the default behavior. However, the English description is outdated and missing this information.
Apply this change to sync the descriptions:
'zh-CN':
'<p>可选择值为<code>medium</code>,<code>default</code>,<code>small</code>,<code>mini</code>,不传递就是默认尺寸。</p>',
- 'en-US': '<p>The value can be <code>medium</code>, <code>small</code>, or <code>mini</code>.</p>'
+ 'en-US': '<p>The value can be <code>medium</code>, <code>default</code>, <code>small</code>, or <code>mini</code>. If not specified, the default size will be used.</p>'
📝 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.
'zh-CN': | |
'<p>可选择值为<code>medium</code>,<code>default</code>,<code>small</code>,<code>mini</code>,不传递就是默认尺寸。</p>', | |
'en-US': '<p>The value can be <code>medium</code>, <code>small</code>, or <code>mini</code>.</p>' | |
'zh-CN': | |
'<p>可选择值为<code>medium</code>,<code>default</code>,<code>small</code>,<code>mini</code>,不传递就是默认尺寸。</p>', | |
'en-US': '<p>The value can be <code>medium</code>, <code>default</code>, <code>small</code>, or <code>mini</code>. If not specified, the default size will be used.</p>' |
PR
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
New Features
Bug Fixes
Tests