Skip to content

Commit

Permalink
Merge pull request #25219 from Tap-Kim/fix-vue3-showcode-attributeSor…
Browse files Browse the repository at this point in the history
…uce-prefix-validation

Vue3: Fix support for `onX` and empty attributes in Show Code
  • Loading branch information
JReinhold authored Jan 24, 2024
2 parents 6733062 + 709b759 commit 3eeb562
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions code/renderers/vue3/src/docs/sourceDecorator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ describe('Vue3: sourceDecorator->attributeSoure()', () => {
it('normal html attribute should not convert to vue event directive', () => {
expect(attributeSource('on-click', () => {})).toMatchInlineSnapshot(`on-click='()=>({})'`);
});
it('The value undefined or empty string must not be returned.', () => {
expect(attributeSource('icon', undefined)).toMatchInlineSnapshot(`icon=""`);
expect(attributeSource('icon', '')).toMatchInlineSnapshot(`icon=""`);
});
it('htmlEventAttributeToVueEventAttribute onEv => v-on:', () => {
const htmlEventAttributeToVueEventAttribute = (attribute: string) => {
return htmlEventToVueEvent(attribute);
Expand Down
4 changes: 2 additions & 2 deletions code/renderers/vue3/src/docs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ const htmlEventAttributeToVueEventAttribute = (key: string) => {
};

const directiveSource = (key: string, value: unknown) =>
key.includes('on')
key.toLowerCase().startsWith('on')
? `${htmlEventAttributeToVueEventAttribute(key)}='()=>({})'`
: `${key}="${value}"`;
: `${key}="${value || ''}"`;

const attributeSource = (key: string, value: unknown, dynamic?: boolean) =>
// convert html event key to vue event key
Expand Down

0 comments on commit 3eeb562

Please sign in to comment.