Skip to content

feat(uui-input): Adds <datalist> options support #1106

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

leekelleher
Copy link
Member

Description

Implements #999.

Adds <datalist> options support to <uui-input>.

Adds an options property to <uui-input>, accepting an array of { name, value } objects, (similar to <uui-select options>). This will result in a <datalist> element being rendered within the Shadow DOM, so that the input can be associated with it via the list attribute.

Types of changes

  • New feature (non-breaking change which adds functionality)

How to test?

// this is an example of array you need to pass to the input component
const options: Array<Option> = [
  { name: 'Carrot', value: 'orange' },
  { name: 'Cucumber', value: 'green' },
  { name: 'Aubergine', value: 'purple' },
  { name: 'Blueberry', value: 'Blue' },
  { name: 'Banana', value: 'yellow' },
  { name: 'Strawberry', value: 'red' },
];

<uui-input .options=${options}></uui-input>

@leekelleher leekelleher added the feature Something we are looking to build label May 22, 2025
Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://delightful-beach-055ecb503-1106.westeurope.azurestaticapps.net

Copy link

Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://delightful-beach-055ecb503-1106.westeurope.azurestaticapps.net

@iOvergaard
Copy link
Contributor

@leekelleher Do we need to do all of the work for the consumer with an .options property? Could they not manually add the <datalist /> element to the default uui-input slot?

My concern is that you cannot use this component outside a JavaScript context, i.e. in "light DOM", if you cannot set the options as HTML.

@leekelleher
Copy link
Member Author

That's correct, the <input> inside the Shadow DOM can't access the <datalist> in the Light DOM (when slotted).

The only option (as far as I'm aware) is to have the <datalist> inside the Shadow DOM too.

I'd have preferred to keep the <datalist> as a separate component. Which is why I'm unsure about this PR. 🤔

@iOvergaard
Copy link
Contributor

That's correct, the <input> inside the Shadow DOM can't access the <datalist> in the Light DOM (when slotted).

That sounds very odd indeed. If you set up the uui-input component with:

render() {
  return html`
    <input type="text" bla="bla" list=${this.list}>
    <slot></slot>
  `
}

To understand the issue correctly, are you saying that this won't work?

<uui-input list="my-options">
  <datalist id="my-options">
    <option value="a">A</option>
  </datalist>
</uui-input>

@leekelleher
Copy link
Member Author

That's correct, as the slotted content would be in the Light DOM.

@iOvergaard
Copy link
Contributor

I found an example of another library that solved it by creating an "input-container" element, where you manually type in the native <input> element. Their container element then provides the styling. That seems to work well, as that gives you exact control of the native elements.

Example here: https://jsbin.com/xojule/edit?html,output
Git repo here: https://github.com/PolymerElements/paper-input

Wonder if we could do something similar, which would also be very useful for uui-select, which currently does not work in Light DOM either:

<uui-input-container>
  <input type="text" list="options">
  <datalist id="my-options">
    <option value="a">A</option>
  </datalist>
</uui-input-container>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Something we are looking to build
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy