electrovir / vira

WIP FOSS design system
https://electrovir.github.io/vira/
Creative Commons Zero v1.0 Universal
1 stars 0 forks source link

ViraInput with fitText: true not updating dynamically. #2

Closed wadlo closed 1 year ago

wadlo commented 1 year ago

Is it intended that ViraInput with fitText: true doesn't update dynamically? If I change the value of the input, then leave the screen and re-enter, it does update, but not while typing in the input field or after clicking out.

Code:

<${ViraInput}
      ${assign(ViraInput, {value: inputs.habit?.getTrigger() ?? "Unknown", fitText: true})}
      ${listen(ViraInput.events.valueChange, (newVal)=>{inputs.habit?.setTrigger(newVal.detail)})}>
</${ViraInput}>
wadlo commented 1 year ago

Nevermind, this was an issue with not updating the internal state.

wadlo commented 1 year ago

Reopening this to propose new behavior. Right now the ViraInput only updates its size if fixedText: true is set and an updateState is called. I'd expect updateState not be required for it to update width. In fact, I'd expect just

<${ViraInput}
   ${assign(ViraInput, {value: "initialText", fitText: true})}
</${ViraInput}>

to automatically update size when the input is changed. Or if that's not possible, at least

<${ViraInput}
   ${assign(ViraInput, {value: inputs.habit?.getTrigger() ?? "Unknown", fitText: true})}
   ${listen(ViraInput.events.valueChange, (newVal)=>{inputs.habit?.setTrigger(newVal.detail);>
</${ViraInput}>

should work.

electrovir commented 1 year ago

I'm not sure what getTrigger is doing, but the input to these elements should always be a state variable that gets updated with updateState. Thus, nothing is going to change unless it's changed with updateState.

The architecture is like this:

wadlo commented 1 year ago

So to make sure I understand,

parent - passes "input" to child. child - child uses "input" and returns "output". parent - receives the "output" from child parent - callse updateState based no the "output" to update "input".

electrovir commented 1 year ago

parent - passes "input" to child. child - child uses "input" and returns "output". parent - receives the "output" from child parent - callse updateState based no the "output" to update "input".

Correct.

My only addition would be that the child will only return "output" (through events) if the input it received needs to change.

electrovir commented 1 year ago

I think this is resolved, as there's no actual issue here, it boils down to a data flow question.