-
Notifications
You must be signed in to change notification settings - Fork 19
OcSelect: add support for showing default values #1634
base: master
Are you sure you want to change the base?
Conversation
2eb371a
to
0860c53
Compare
0860c53
to
910a002
Compare
SonarCloud Quality Gate failed. |
<div class="oc-docs-width-medium"> | ||
<oc-select v-model="selected" :options="['Apple', 'Bannana', 'Orange', 'Pear']" default-value="Orange" /> | ||
<p> | ||
Selected: {{ selected === null ? "null" : selected }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Selected: {{ selected === null ? "null" : selected }} | |
Selected: {{ selected || "null" }} |
</template> | ||
</vue-select> | ||
<div> | ||
<label :for="id" v-text="label" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<label :for="id" v-text="label" /> | |
<label :for="id" class="oc-label" v-text="label" /> |
Just checked how the update journey in web
would look like and we seem to give all labels this class, which doesn't style anything initially but sometimes is used to target the label for styling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense but possibly belongs into the original pr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but that one is merged already (and I somehow ended here without understanding this is not the original ;D my bad, could you include it either way?
@@ -128,6 +172,23 @@ export default { | |||
*/ | |||
this.$emit("search:input", event.target.value) | |||
}, | |||
onInput(value) { | |||
// selecting a value is handled via onOptionSelecting, we just nead to handle clear events here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*need
return listeners | ||
}, | ||
showClearButton() { | ||
return this.clearButtonEnabled && this.value !== null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.disabled
needs to be taken into account.
(depends on #1633)
Description
I've added an optional
defaultValue
prop toOcSelect
.The value provided there is selected when
value === null
. When the default value is shown the clear button is hidden because you obviously can't clear the default.It's possible to select the default value which then fires the
input
event, i.e. a user can override a default value by explicitly setting it.I'm not really happy with the usability of this as it is right now for multiple reasons:
x
and then seeing some value is confusingx
and then still seeing the same value is even more confusing(when the default was explicitly selected by the user)
OcTextInput
andOcTextarea
I figured it might be a bit better if we would use a different icon for "reverting to default", e.g. something like the replay icon provided by ODS. Unfortunately vue-select does not seem to provide api to replace the clear button: https://github.com/sagalbot/vue-select/blob/4230bba9349c5e3ba33a4e77a566fe3ff7d2e1c5/src/components/Select.vue#L58
If we decide to somehow display the default outside of the actual select component we need to make sure we respect
label
and possibly other relevant props.We need to decide if we want to settle on
clearButtonEnabled
orclearable
(...or whatever) as name for this kind of property.vue-select
usesclearable
,OcTextInput
usesclearButtonEnabled
. I'm fine with whatever, although I personally likeclearable
a bit better I choseclearButtonEnabled
for not having to introduce a breaking change inOcTextInput
...Related Issue
Motivation and Context
I want to show a default value in ownBrander 2.0 if a user hasn't selected a value yet.
It's possible to handle this outside of the OcSelect component, but that's rather cumbersome and dealing with the vue-select events seem a bit brittle, which is why I would prefer to have this solved for once in ODS. With the additional benefit that my code wouldn't depend on vue-select and vue-select could be replaced better (if neccessary one day).
Moreover, this needs to be thought through UX wise and having a solution in ODS would avoid different approaches in different places.
How Has This Been Tested?
Screenshots (if appropriate):
Showing the default:
Default selected explicitly:
Types of changes
Checklist:
Open tasks: