Kong / kongponents

🦍 Kong Vue Component Library
https://kongponents.konghq.com
Apache License 2.0
121 stars 19 forks source link

fix: duplicate ids #2238

Closed Leopoldthecoder closed 1 month ago

Leopoldthecoder commented 1 month ago

Summary

This PR fixes a bug where assigning id to KFileUpload and KSelect results in duplicate ids on the page.

KFileUpload

Before After
image image
  1. Use inheritAttrs: false to avoid directly binding attributes to the root element. Instead, strip id from attributes and explicitly assign them.
  2. Remove v-bind-once="{ id: inputId }" because according to the Vue doc and v-bind-once's implementation, adding v-bind-once="{ id: inputId }" on a custom component binds id to the root element of the custom component, regardless of its inheritAttrs configuration. Instead, use :id="inputId" so that KInput can bind the id to the <input> element.

KSelect

Before After
image image
  1. Remove v-bind-once="{ id: selectId }" for the same reason as the second bullet point above. KSelect already binds attributes to KInput.

PR Checklist

netlify[bot] commented 1 month ago

Deploy Preview for kongponents-sandbox ready!

Name Link
Latest commit c957be707235842a3f82ccd07bd36aa0ca2f2362
Latest deploy log https://app.netlify.com/sites/kongponents-sandbox/deploys/6670482d1728a800088ed926
Deploy Preview https://deploy-preview-2238--kongponents-sandbox.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] commented 1 month ago

Deploy Preview for kongponents ready!

Name Link
Latest commit c957be707235842a3f82ccd07bd36aa0ca2f2362
Latest deploy log https://app.netlify.com/sites/kongponents/deploys/6670482d7f4f5d0008cb1d77
Deploy Preview https://deploy-preview-2238--kongponents.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

adamdehaven commented 1 month ago

@Leopoldthecoder if I apply a custom id attribute to a KSelect, I'm not seeing the id duplicated anywhere. Am I missing something?

Leopoldthecoder commented 1 month ago

@Leopoldthecoder if I apply a custom id attribute to a KSelect, I'm not seeing the id duplicated anywhere. Am I missing something?

How did you set up your env? In my case, I pulled the latest code from alpha, added id in this block, and ran pnpm run sandbox:dev:

<KSelect
+ id="my-select"
  v-model="asyncItemsModel"
  clearable
  enable-filtering
  enable-item-creation
  :items="asyncItems"
  :loading="asyncItemsLoading"
  @item-added="handeAsyncItemAdded"
  @item-removed="handeAsyncItemRemoved"
  @query-change="asyncQueryChange"
>