bootstrap-select icon indicating copy to clipboard operation
bootstrap-select copied to clipboard

Not working on react

Open melvinotieno opened this issue 5 years ago • 8 comments

I have added all the dependencies required in react including jquery. However, the select is never rendered on the browser

melvinotieno avatar Jul 24 '20 22:07 melvinotieno

Any update?

ismailcse11 avatar Sep 10 '20 23:09 ismailcse11

nope still not working

melvinotieno avatar Sep 12 '20 16:09 melvinotieno

The component works fine with the Boostrap 3 but it doesn't want to work with the bootstrap 4, a strange behavior.

marlenesco avatar Nov 10 '20 16:11 marlenesco

Still not reliably working with Chrome 91.0.4472.114, Bootstrap 4.3.1 and React v16.11. However, I got it displayed when using it on "top-level" of the component hierarchy, i.e. directly in the JSX of a component mounted in the router. If I place it into a child of this level, it also disappears for me. Any plans to fix this? Any news from other guys experiencing the issue? Any workarounds known? Or is there a good alternative on the market which I just wasn't able to find?

jebbard avatar Jul 09 '21 06:07 jebbard

Just an update from my end: I found out that it seems to work if you DO NOT use any hooks in the react component containing the selectpicker. So once I commented out const { t } = useTranslation(...) it displays for me and works as expected. I guess that might at least open up some possibilities, at least for use in child componnents which usually do not need too many hooks (despite, probably, i18n stuff...).

Here an example component were I got it running with the setup mentioned in my previous post:

import React from 'react';
import { AttributePropertiesTO } from '../../services/utils/lists/api/AttributePropertiesTO';

type FilterSearchViewProps = {
    selectedAttributId: string;
    attributes: AttributePropertiesTO[];
};

export default function FilterSearchView(props: FilterSearchViewProps) {
    //const { t } = useTranslation(NS_ENUMS.name);

    return (
        <select className="selectpicker" data-live-search="true">
            <option data-tokens="ketchup mustard">Hot Dog, Fries and a Soda</option>
            <option data-tokens="mustard">Burger, Shake and a Smile</option>
            <option data-tokens="frosting">Sugar, Spice and all things nice</option>
        </select>
    );
}

jebbard avatar Jul 09 '21 07:07 jebbard

This might help: https://github.com/snapappointments/bootstrap-select/issues/2328#issuecomment-616293733

NicolasCARPi avatar Jul 09 '21 11:07 NicolasCARPi

For me I import load script at useEffect function and it's seem work correctly.

import React, {useEffect} from "react";
import $ from "jquery"
import "bootstrap-select/dist/css/bootstrap-select.min.css";
import "bootstrap-select/dist/js/bootstrap-select";
const dialCodes = require("../assets/dial.json");

export default function PhoneCodeSelector({
    phone_code,
    handleInputChange
}) {
  useEffect(() => {
    $('.selectpicker').selectpicker(); // -> add load script. Magic here
    $('.bootstrap-select ul.dropdown-menu').addClass("show"); // -> Fix picker dropdown don't render data
  }, [])
    return (
        <select 
        value = {phone_code}
        type="select" 
        name="phone_code"
        style = {{maxWidth: '200px'}} 
        className  = "selectpicker"
        onChange={handleInputChange}
      >
        {dialCodes.map(dial => (
            <option 
              value = {dial.dial_code} 
              key = {`phone_key_${dial.dial_code}`}
              title = {dial.dial_code}
              data-content = {`<div class = \'d-flex justify-content-between\'> <span>${dial.name}</span> <span>${dial.dial_code}</span> </div>`}
            >
              {`${dial.dial_code} (${dial.name})`}
            </option>
        ))}
      </select>
    )
}

gys-dev avatar Oct 14 '21 03:10 gys-dev