question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vue3 default prop (string) value is wrapped in quotes

See original GitHub issue

Describe the bug When using a default value for a string type prop, like the below example, Storybook will wrap it in quotes failing the validation and breaking the component.

    defaultOrder: {
      type: String,
      default: 'desc',
      validator: (value: string) => ['desc', 'asc'].includes(value),
    },

This results in the following control: image

Which is actually the string "desc" instead of just desc, breaking the component.

To Reproduce Add my prop to a component and create a story for it.

Expected behavior The string value to not be wrapped.

Screenshots See above.

System

  System:
    OS: macOS 11.2.1
    CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
  Binaries:
    Node: 12.19.0 - ~/.nvm/versions/node/v12.19.0/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v12.19.0/bin/yarn
    npm: 6.14.10 - ~/.nvm/versions/node/v12.19.0/bin/npm
  Browsers:
    Chrome: 88.0.4324.192
    Edge: 88.0.705.74
    Firefox: 81.0.2
    Safari: 14.0.3
  npmPackages:
    @storybook/addon-actions: ^6.2.0-beta.2 => 6.2.0-beta.2
    @storybook/addon-essentials: ^6.2.0-beta.2 => 6.2.0-beta.2
    @storybook/addon-links: ^6.2.0-beta.2 => 6.2.0-beta.2
    @storybook/vue3: ^6.2.0-beta.2 => 6.2.0-beta.2

Additional context We’re using MDX files for the stories, not sure if this also happens in regular story JS files.

┆Issue is synchronized with this Asana task by Unito

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
TheDutchCodercommented, Mar 11, 2021

All working, excellent work!

1reaction
TheDutchCodercommented, Feb 25, 2021

Okay I found that if I strictly type my property it does work, so there must be some TS magic happening:

type SortOrder = 
  | 'desc'
  | 'asc'

// ...

    defaultOrder: {
      type: String as PropType<SortOrder>,
      default: 'desc',
      validator: (value: string) => ['desc', 'asc'].includes(value),
    },
Read more comments on GitHub >

github_iconTop Results From Across the Web

vue.js - Vuejs component props as string
If you want to specify a string value in that inline expression, you can wrap the value in quotes to make it a...
Read more >
Props | Vue.js
All props are optional by default, unless required: true is specified. · An absent optional prop other than Boolean will have undefined value....
Read more >
Guide to Vue Props
In this guide, learn what Vue props are, how to register and use them, how to pass data using props, validate them, set...
Read more >
How to use variables in CSS with v-bind in VueJs 3
The variable need to be wrapped into a v-bind method. ... me</button> </template> <script> export default { props: { colour: String } ...
Read more >
Vue 3 Script Setup, The Future Of Vue? Tutorial And Setup
Vue.js has a new Script Setup feature that is changing the way you create Vue apps. Should you use it? In this video...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found