carbon-design-system / carbon-components-vue

Vue implementation of the Carbon Design System
http://vue.carbondesignsystem.com
Apache License 2.0
609 stars 179 forks source link

cv-radio-button causes warnings about values that are not strings #483

Closed dyc3 closed 5 years ago

dyc3 commented 5 years ago

Detailed description

Describe in detail the issue you're having.

I have a component that uses radio buttons, and the values are bound to numeric variables. The radio button expects the value attribute to be a String, so Vue warns when it's not a string.

[Vue warn]: Invalid prop: type check failed for prop "value". Expected String with value "1", got Number with value 1.

However, this does not prevent the component I made from working as expected.

Is this a feature request (new component, new icon), a bug, or a general issue?

bug

Is this issue related to a specific component?

Yes, cv-radio-button

What did you expect to happen? What happened instead? What would you like to see changed?

I expected to be able to use the carbon radio buttons with any type of value that normal radio buttons allow.

Steps to reproduce the issue

  1. Create a cv-radio-button.
  2. Bind value to a variable that is not a string.
  3. View in browser and observe console.

Additional information

lee-chase commented 5 years ago

We have tried to be careful when it comes to standard attributes. They have intentionally not been used for other purposes. In the case of checkbox value, it is a string in the underlying component.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio https://codepen.io/lee-chase/pen/831dc22f01f0891df0e6d9ebf6c94956

If the radio button, along with other components, allowed the passing of non-string values we would need to either ensure they can be coerced into a string or provide our own value which would affect form usage.

There is also the question as to whether events raised by the component should return the same type.

I believe the correct solution is for you to pass a string and expect a string in return.

lee-chase commented 5 years ago

Sorry, didn't mean to close. Meant to start a conversation first ;-)

dyc3 commented 5 years ago

Ah, that makes sense. In that case, I think the better decision would be to leave it as it is.