Skip to content

feat(autocomplete): [autocomplete] update autocomplete demos #2384

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

Merged
merged 2 commits into from
Oct 24, 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
43 changes: 37 additions & 6 deletions examples/sites/demos/pc/app/autocomplete/size-composition-api.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
<template>
<div class="demo-autocomplete">
<tiny-autocomplete
size="medium"
v-model="value"
:fetch-suggestions="querySearch"
placeholder="请输入内容"
></tiny-autocomplete>
<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>
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

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.

Suggested change
<div class="title">small:</div>
<div class="title">mini:</div>

<tiny-autocomplete
size="mini"
v-model="value"
:fetch-suggestions="querySearch"
placeholder="请输入内容"
></tiny-autocomplete>
</div>
</div>
</template>

Expand Down Expand Up @@ -65,4 +90,10 @@ function loadAll() {
.demo-autocomplete .tiny-autocomplete {
width: 270px;
}
.demo-autocomplete > div {
margin-top: 12px;
}
.demo-autocomplete > div > .title {
line-height: 26px;
}
</style>
13 changes: 10 additions & 3 deletions examples/sites/demos/pc/app/autocomplete/size.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ import { test, expect } from '@playwright/test'
test('size', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
await page.goto('autocomplete#size')
await page.getByRole('textbox', { name: '请输入内容', exact: true }).click()
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()
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

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.

Suggested change
const meiumSize = demo.locator('.tiny-autocomplete').first()
const mediumSize = 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)
Comment on lines +7 to +10
Copy link

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.


await expect(meiumSize).toHaveCSS('height', '40px')
await expect(defaultSize).toHaveCSS('height', '32px')
await expect(smallSize).toHaveCSS('height', '28px')
await expect(miniSize).toHaveCSS('height', '24px')
})
43 changes: 37 additions & 6 deletions examples/sites/demos/pc/app/autocomplete/size.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
<template>
<div class="demo-autocomplete">
<tiny-autocomplete
size="medium"
v-model="value"
:fetch-suggestions="querySearch"
placeholder="请输入内容"
></tiny-autocomplete>
<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>
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

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.

Suggested change
<div class="title">small:</div>
<div class="title">mini:</div>

<tiny-autocomplete
size="mini"
v-model="value"
:fetch-suggestions="querySearch"
placeholder="请输入内容"
></tiny-autocomplete>
</div>
Comment on lines +3 to +33
Copy link

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']
  }
}

</div>
</template>

Expand Down Expand Up @@ -72,4 +97,10 @@ export default {
.demo-autocomplete .tiny-autocomplete {
width: 270px;
}
.demo-autocomplete > div {
margin-top: 12px;
}
.demo-autocomplete > div > .title {
line-height: 26px;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ export default {
{
demoId: 'size',
name: {
'zh-CN': '输入框大小',
'zh-CN': '尺寸',
'en-US': 'Text box size'
},
desc: {
'zh-CN': '<p>可选择值为<code>medium</code>,<code>small</code>,<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>small</code>, or <code>mini</code>.</p>'
Comment on lines +36 to 38
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

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.

Suggested change
'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>'

},
codeFiles: ['size.vue']
Expand Down
Loading