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

Select does not work when creating dynamic ranges #223

Closed
quasaray opened this issue Jun 11, 2023 · 12 comments
Closed

Select does not work when creating dynamic ranges #223

quasaray opened this issue Jun 11, 2023 · 12 comments
Labels
bug Something isn't working

Comments

@quasaray
Copy link

I have a dynamic range, for selecting the start and end of an interval, which uses two select inputs for choosing the start and end.

Whenever the range changes though, the newly added values are not selectable. The values still display on the select, but clicking on them does not update the select value.
e.g if the start value has [1,2] but is then expanded to [1,2,3], 1 and 2 can be selected, but 3 cannot.

I have created a stackblitz reproducing the problem here, changing the end value to a larger number will update the display of the start values, but it can only select what was originally present.

Is the Select component not intended for dynamic menus? I could not see anything in the documentation about it.

@juanrgm juanrgm added the bug Something isn't working label Jun 13, 2023
@juanrgm
Copy link
Member

juanrgm commented Jun 13, 2023

There is a bug in inspectChildren.

The children introspection is a common pattern in ReactJS, but nonexistent in SolidJS. I don't know if this case can be fixed, otherwhise I would have to use contexts. I need to investigate further.

@ghost
Copy link

ghost commented Jun 30, 2023

Also having this issue. Glad I finally found a post about it because I thought it was just me 😅

@urish
Copy link

urish commented Jul 12, 2023

Same here - any workarounds?

@quasaray
Copy link
Author

native select still works fine, I am using that for now

@lukexor
Copy link

lukexor commented Nov 30, 2023

It seems like this might also be an issue for buildless environments? Even when not using dynamic options. No onChange triggered. NativeSelect works fine as well, though less ideal as I also want to use the multi select chip component in this environment. and the Native version of multiselect doesn't seem to work correctly (I can't seem to get it working in a normal solid build either)

e.g.

  const [value, setValue] = createSignal(props.defaultValue);
  return html`
    <${Show} when=${props.visible}>
      <div class="py-4">
        <${InputLabel}>${props.name}${" "}<//>
        <${Select}
          title=${props.title}
          label=${props.name}
          name=${props.name}
          value=${value}
          disabled=${props.disabled}
          fullWidth=${() => props.fullWidth ?? true}
          onChange=${(e) => setValue(e.target.value)}
        >
          <${Show} when=${() => !props.required}>
            <${MenuItem} value="">
              <em>None</em>
            <//>
          <//>
          <${MenuItem} value="1">
            <em>Item 1</em>
          <//>
        <//>
      </div>
    <//>
  `;

@BierDav
Copy link
Contributor

BierDav commented Dec 8, 2023

Hi guys! I have created an SSR compatible version of the select component here. You can check it out, unfortunately it is not compatible with the Select API of MUI, but that is as close as I it gets, I guess, and I also support dynamic ranges with <For/> component

@urish
Copy link

urish commented Apr 16, 2024

Same here - any workarounds?

My current workaround is the wrap the Select elements with <Show>, and hide / reshow them whenever the value list changes.

@Azq2
Copy link

Azq2 commented Apr 26, 2024

If I understand correctly, the whole problem is that in SolidJS it is impossible to get the properties of child elements - the DOM node is returned instead.

solidjs/solid#222


As another workaround, I suggest WeakMap with all MenuItem's. Why not?
Only what we need - find all .MuiMenuItem-root in the props.children and then convert to the props using WeakMap.

https://playground.solidjs.com/anonymous/65cf3993-1671-4d44-9e45-f85380b2028b

@BierDav
Copy link
Contributor

BierDav commented Apr 28, 2024

That's a good point, i haven't ever heard of that until now, but it seems to solve the technical issues i had. Unfortunately i currently don't have a lot of time, to implement this but I could offer to review the pr.

@Azq2
Copy link

Azq2 commented Apr 28, 2024

PR is here: #292

@cs-clarence
Copy link

Temporary fix for me is use

Array.map and jsx interpolation

<Select>
  {names()?.map((name) => (
    <MenuItem value={name}>
      {name}
    </MenuItem>
  ))}
</Select>

instead of

<Select>
  <For each={names()}>
    {(name) => (
      <MenuItem value={name}>
        {name}
      </MenuItem>
    )}
  </For>
</Select>

@Azq2
Copy link

Azq2 commented Aug 12, 2024

@juanrgm juanrgm closed this as completed in b196443 Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants