简体   繁体   English

react-bootstrap-typeahead 默认样式

[英]react-bootstrap-typeahead default styling

I am trying to use react-bootstrap-typeahead in my project.我正在尝试在我的项目中使用 react-bootstrap-typeahead。 The problem is that formatting looks pretty awful.问题是格式化看起来很糟糕。 I tried running the exact same code in an online sandbox.我尝试在在线沙箱中运行完全相同的代码。 There it looks fine.那里看起来不错。

在此处输入图像描述

At first i thought that the sandbox is applying explicit styles, but that does not seem to be the case.起初我认为沙盒正在应用显式样式,但似乎并非如此。 As far as i can tell, it is using the default styling of the typeahead competent instead of applying heavy formatting.据我所知,它使用的是 typeahead 主管的默认样式,而不是应用重格式。 https://codesandbox.io/s/9jq9jyzmry https://codesandbox.io/s/9jq9jyzmry

I suspect that something in my app is overriding the styling used by the typeahead and leading to it being improperly rendered.我怀疑我的应用程序中的某些东西覆盖了预输入使用的样式并导致它被不正确地呈现。

I realize it is possible to apply custom formatting to the typeahead, but that feels laborious.我意识到可以将自定义格式应用于预输入,但这感觉很费力。 Is there a way to force default styling on the typeahead?有没有办法强制预先输入的默认样式?

For reference, here's the code:作为参考,下面是代码:

import React, { useState } from 'react';
import { Typeahead } from 'react-bootstrap-typeahead';

const MyPicker = () => {
  const [selected, setSelected] = useState([]);
  const handleChange = (sel) => setSelected(sel);
  return (
    <div>
      <Typeahead
        multiple
        clearButton
        id="my-typeahead"
        labelKey="fullname"
        onChange={handleChange}
        options={[
          {
            fullname: 'Apple',
          },
          {
            fullname: 'Banana',
          },
          {
            fullname: 'Peach',
          },
          {
            fullname: 'Zucchini',
          },
        ]}
        placeholder="Select options..."
        selected={selected}
      />
    </div>
  );
};

export default MyPicker;

Figured it based on this question: CSS not loading correctly With React-bootstrap-typeahead根据这个问题想出来: CSS not loading correct With React-bootstrap-typeahead

The actual solution was to run npm install bootstrap on my project and then add import 'bootstrap/dist/css/bootstrap.min.css';实际的解决方案是在我的项目上运行npm install bootstrap然后添加import 'bootstrap/dist/css/bootstrap.min.css'; to my component.到我的组件。

Still don't quite understand why that import is not needed in the sandbox environment.仍然不太明白为什么在沙盒环境中不需要导入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 验证React-Bootstrap-Typeahead输入 - Validating React-Bootstrap-Typeahead input 实现组合框行为以进行react-bootstrap-typeahead - Achieve combobox behavior for react-bootstrap-typeahead 如何从 react-bootstrap-typeahead 中的嵌套 object 中过滤? - How to filter from nested object in react-bootstrap-typeahead? 需要 react-bootstrap-typeahead 时 Grunt browserify 失败 - Grunt browserify fails when requiring react-bootstrap-typeahead 在内部输入焦点上选择react-bootstrap-typeahead内部的所有文本 - Selecting all text inside react-bootstrap-typeahead on inner input focus React-Bootstrap-TypeAhead 在尝试更改已选择的选项时给出错误 - React-Bootstrap-TypeAhead giving error when trying to change already selected option react-bootstrap-typeahead 错误:从生命周期方法内部调用了 flushSync - react-bootstrap-typeahead error: flushSync was called from inside a lifecycle method 设置typeahead.js列表的样式(引导方式) - Styling the typeahead.js list (the bootstrap way) 反应<typeahead>设置默认值</typeahead> - React <Typeahead> set default value 在React TypeAhead Bootstrap中将变量传递给`renderMenuItemChildren` - Passing a variable to `renderMenuItemChildren` in react typeahead bootstrap
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM