Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support input#list #29217

Open
3 tasks done
oliveryasuna opened this issue Mar 25, 2024 · 3 comments
Open
3 tasks done

feat: Support input#list #29217

oliveryasuna opened this issue Mar 25, 2024 · 3 comments
Labels
type: feature request a new feature, enhancement, or improvement

Comments

@oliveryasuna
Copy link

Prerequisites

Describe the Feature Request

Add the list property to <ion-input>.

<ion-input list="my-list"/>
<!-- OR React -->
<IonInput list="my-list"/>
<!-- OR whatever syntax for other frameworks. -->

<datalist id="my-list">
  ...
</datalist>

Is there a reason it is not supported? Perhaps because it does not represent native text field behavior? Note: There is very little styling possible on <datalist>.

Describe the Use Case

To connect to a <datalist> in order to show suggestions.

Describe Preferred Solution

No response

Describe Alternatives

Here is my current workaround:

<IonItem className="ion-no-padding">
  {/*This is a hack to make sure the input below is styled.*/}
  <IonInput style={{display: 'none'}}/>
  {/*TODO: Platform-dependent class names.*/}
  <div className="sc-ion-input-ios-h sc-ion-input-ios-s ios input-label-placement-start in-item">
    <label htmlFor="code" className="input-wrapper sc-ion-input-ios">
      <div className="label-text-wrapper label-text-wrapper-hidden sc-ion-input-ios sc-ion-input-ios-s"></div>
      <div className="native-wrapper sc-ion-input-ios sc-ion-input-ios-s">
        <input
            name="code"
            type="text"
            autoCapitalize="none"
            autoComplete="off"
            autoCorrect="off"
            spellCheck="false"
            placeholder="or enter code"
            list="codes"
            className="native-input sc-ion-input-ios"/>
        <datalist id="codes">
          <option>aaa</option>
          <option>aab</option>
          <option>aac</option>
          <option>cca</option>
          <option>ccb</option>
          <option>ccc</option>
        </datalist>
      </div>
    </label>
  </div>
</IonItem>

Related Code

No response

Additional Information

No response

@ionitron-bot ionitron-bot bot added the triage label Mar 25, 2024
@brandyscarney brandyscarney added the type: feature request a new feature, enhancement, or improvement label Mar 25, 2024
@brandyscarney brandyscarney removed their assignment Mar 25, 2024
@jberglinds
Copy link

I'm looking for this too.
In my React project, I've solved it like this for now:

<IonInput
  ref={async (node) => {
    const input = await node?.getInputElement();
    input?.setAttribute("list", "codes");
  }}
  label="Code"
  type="text"
/>
<datalist id={"codes"}>
  <option value={"aaa"} />
  <option value={"aab"} />
  <option value={"aac"} />
  ...
</datalist>

@oliveryasuna
Copy link
Author

I'm looking for this too. In my React project, I've solved it like this for now:

<IonInput
  ref={async (node) => {
    const input = await node?.getInputElement();
    input?.setAttribute("list", "codes");
  }}
  label="Code"
  type="text"
/>
<datalist id={"codes"}>
  <option value={"aaa"} />
  <option value={"aab"} />
  <option value={"aac"} />
  ...
</datalist>

I feel silly for not thinking of this!

@oliveryasuna
Copy link
Author

@jberglinds Actually, your solution seems to cause a bug. You have to click the input multiple times for it to show the datalist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request a new feature, enhancement, or improvement
Projects
None yet
Development

No branches or pull requests

3 participants