twilio-labs / paste

Paste is a design system for designing and building consistent experiences at Twilio.
https://paste.twilio.design
MIT License
440 stars 115 forks source link

Base comboboxes ignore programmatic input update #3919

Closed vpavlovskii closed 4 days ago

vpavlovskii commented 4 months ago

Description

Hey there! There is an issue with setting combobox input from code. The below examples clearly demonstrate the issue:

import {Combobox} from '@twilio-paste/core'
import {useState} from 'react'

export const IssueWithInput = () => {
  const [input, setInput] = useState<string>("0");

  const items = ["1", "2", "3"]

  if (input != "42") setInput("42")

  return (
    <Combobox
      items={items}
      inputValue={input} // "42" must be finally displayed 
      selectedItem={items[0]}
      autocomplete
      labelText="IssueWithInput"/>
  )
}
import {Combobox, useCombobox} from '@twilio-paste/core'
import {useState} from 'react'

export const NoIssueWithInput = () => {
  const [input, setInput] = useState<string>("0");

  const items = ["1", "2", "3"]

  if (input != "42") setInput("42")

  const state = useCombobox({
    items: items,
    inputValue: input,
    selectedItem: items[0],
  });

  return (
    <Combobox
      state={state}
      items={items}
      autocomplete
      labelText="NoIssueWithInput"/>
  )
}

And the resulting view is the following:

Screenshot 2024-05-27 at 13 35 38

Link to Reproduction

https://just.check.the.examples.above

Steps to reproduce

  1. Go to '...'
  2. Click on '...'
  3. Scroll down to '...'
  4. See error

Paste Core Version

@twilio-paste/core: 20.12.0

Browser

Google Chrome 125.0.6422.113

Operating System

Additional Information

No response

nkrantz commented 4 months ago

Hey @vpavlovskii - just a heads up that we're pretty low on eng capacity at the moment. That being said I'm going to try to take a look and if it turns out to be a Combobox but I'll create a JIRA ticket and try to prioritize it in an upcoming sprint.

First, in order to help me understand your problem a little better, why do you need to use a Combobox without using the useCombobox() hook? It seems to me that if you just pass the returned state from the hook to your component, you won't have any issues with what you're trying to achieve.

nkrantz commented 4 months ago

Hey @vpavlovskii - just want to check in here. Are you still experiencing the issue or are you okay using the hook? Let me know, otherwise I'll close this Issue for now.