所以我正在尝试设置 react-select 组件的输入字段的样式。不幸的是,字体系列被标准输入元素覆盖,因为样式被应用于包装器 div 而不是输入字段本身。
input: () => ({
fontFamily: `${theme.fonts.tabs.family} !important`,
fontWeight: theme.fonts.tabs.weight,
fontSize: 18,
color: theme.colors.secondary,
height: 24
}),
Run Code Online (Sandbox Code Playgroud)
我将如何在不使用类名的情况下更改 fontFamily?
我正在尝试将用于react-select多选指示器的图标更改为字体很棒的图标,但它不起作用。知道为什么吗?
import React from "react";
import Select, { components } from "react-select";
import { colourOptions } from "./docs/data";
const Placeholder = props => {
return <components.Placeholder {...props} />;
};
const CaretDownIcon = () => {
return <i className="fas fa-caret-down" />;
};
const DropdownIndicator = props => {
return (
<components.DropdownIndicator {...props}>
<CaretDownIcon />
</components.DropdownIndicator>
);
};
export default () => (
<Select
closeMenuOnSelect={false}
components={{ Placeholder, DropdownIndicator }}
placeholder={"Choose"}
styles={{
placeholder: base => ({
...base,
fontSize: "1em",
color: colourOptions[2].color, …Run Code Online (Sandbox Code Playgroud) 我正在使用react-select从 api 加载结果并使用lodash.debounce对查询进行去抖动:
import React, {useState} from 'react';
import AsyncSelect from 'react-select/lib/Async';
import debounce from 'lodash.debounce';
import {search} from './api';
const _loadSuggestions = (query, callback) => {
return search(query)
.then(resp => callback(resp));
};
const loadSuggestions = debounce(_loadSuggestions, 300);
function SearchboxTest() {
const [inputValue, setInputValue] = useState("");
const onChange = value => {
setInputValue(value);
};
return (
<AsyncSelect
value={inputValue}
loadOptions={loadSuggestions}
placeholder="text"
onChange={onChange}
/>
)
}
Run Code Online (Sandbox Code Playgroud)
当我第一次在搜索框中输入某些内容时,它似乎工作正常(查询已去抖动并且建议已正确填充),但如果我尝试输入新值,则会按预期触发第二个提取查询,但建议来自不会显示第二个调用(并且我没有收到 react-select 显示的“正在加载...”消息)。
当我不去抖动呼叫时,问题似乎消失了(对于第一次和任何后续呼叫):
import React, {useState} from 'react';
import …Run Code Online (Sandbox Code Playgroud) 我想使用react-select作为ag-grid的自定义单元格编辑器
这是代码沙箱链接
您可以在此处下载源代码
npm install
npm start
Run Code Online (Sandbox Code Playgroud)
我已经删除了所有的css,因此看起来很普通,但是仍然可以完成工作。
这是我的package.json
{
"name": "Test",
"version": "1.5.0",
"private": true,
"dependencies": {
"react": "16.8.1",
"react-dom": "16.8.1",
"react-select": "^2.4.1",
"react-scripts": "2.1.5",
"ag-grid-community": "20.1.0",
"ag-grid-react": "20.1.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"deploy": "npm run build",
"lint:check": "eslint . --ext=js,jsx; exit 0",
"lint:fix": "eslint . --ext=js,jsx --fix; exit 0",
"install:clean": "rm -rf node_modules/ && rm -rf package-lock.json && npm install && npm start" …Run Code Online (Sandbox Code Playgroud) 我正在使用 react-hook-forms Controller api 围绕来自 react-select 的 AsyncSelect 加载选项,因为用户从外部 API 键入。一切正常,除了返回的值作为字符串"[object Object]"而不是对象的 fullName 属性返回。
我的组件:
<Controller
control={control}
name="businessCategory"
as={
<AsyncSelect
className="react-select-container"
loadOptions={v => handleAutocompleteLookup(v)}
onChange={handleCategoryInputChange}
getOptionLabel={option => option.name}
getOptionValue={option => option.fullName}
/>
}
/>
Run Code Online (Sandbox Code Playgroud)
我的 handleChange 函数。SetValue 来自 react-hook-form:
const handleCategoryInputChange = newValue => {
return setValue('businessCategory', newValue, true);
};
Run Code Online (Sandbox Code Playgroud)
我的任何数据都是具有以下形状的对象数组:
{
fullName: "DJ service"
id: "gcid:dj"
name: "DJ service"
publisher: "GMB"
}
Run Code Online (Sandbox Code Playgroud)
任何有关这方面的线索将不胜感激,谢谢!
我使用的是@coreui/react与React-select问题是,返回Select的元素scoped slots符core-ui的功能就像搜索和排序
但是,如果在返回带有文本Ex 的a<label>或 a时它工作正常:<p><label>{item.status}</label>
题
为什么 Select 组件会破坏功能?
任何解决方法/努力都受到高度赞赏
笔记
我尝试过类似的解决方法<p hidden >{item.status}</p>,然后渲染Select组件,但它不起作用
import React from "react";
import Select from "react-select";
import { CDataTable } from "@coreui/react";
...
<CDataTable
bordered
clickableRows
fields={fields}
hover
items={[...employeeData]}
itemsPerPage={10}
itemsPerPageSelect
loading={tableLoader}
onRowClick={(e) => rowSelectHandler(e)}
pagination
size="sm"
sorter={{ resetable: true }}
striped
tableFilter={{
placeholder: "Filter",
label: "Search:",
}}
scopedSlots={{
status: (item, …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试使用反应选择来设置选择框的边框颜色,我已经设法做到了这一点,但由于某种原因,当我激活选择框并将鼠标悬停在选项上时,选择框边框颜色的样式默认返回到蓝色。我似乎无法找到 DOM 中我需要定位的位置来更改此设置。问题是这样的:
当我悬停时,会显示正确的(橙色)边框颜色:
但是,当我将鼠标悬停在选项上时,默认的蓝色会显示在选择框周围。我希望它保持橙色:
这是我对选择框的实现。
const customStyles = {
control: (provided: Record<string, unknown>) => ({
...provided,
height: 52,
'&:hover': {
border: '1px solid #ff8b67',
boxShadow: '0px 0px 6px #ff8b67',
},
'&:focus': {
border: '1px solid #ff8b67',
boxShadow: '0px 0px 6px #ff8b67',
},
}),
};
export default function CustomControl(): JSX.Element {
// TODO: select defaultValue by user locale preference possibly
return (
<Select
className="cult-select-box"
styles={customStyles}
defaultValue={countriesJSON[0]}
formatOptionLabel={formatOptionLabel}
options={countriesJSON}
/>
);
Run Code Online (Sandbox Code Playgroud)
谁能明白为什么会发生这种情况?
新的v2 react-select控件非常棒,但默认情况下太大了.是否有(最好)简单的方法将高度降低到与标准选择控件相同(使用Bootstrap v3)?
我正在尝试使用 yup 概念实现对 react-select(单选)的验证。但我收到此错误:
对象作为 React 子对象无效(找到:带有键 {label, value} 的对象)。如果您打算渲染一组子项,请改用数组。
我想知道如何在验证模式中为 yup 概念分配对象
<Formik
initialValues={{
department:"",
}}
onSubmit={this.submitForm}
validationSchema={Yup.object().shape({
department: Yup.object().shape({
label: Yup.string().required(),
value: Yup.string().required(),
}),
})}>
{ props => {
const {
values,
touched,
errors,
isSubmitting,
handleChange,
handleBlur,
handleSubmit,
selectedOption
} = props;
return (
<React.Fragment>
<InputLabel shrink htmlFor={'department'}>
Department</InputLabel>
<Select
inputId="department"
options={options}
value={values.department}
onChange={this.onChangeOption}
onBlur={handleBlur}
/>
{errors.department && touched.department && ( {errors.department} )}
Submit </div> </React.Fragment> ); }}
Run Code Online (Sandbox Code Playgroud) 我想知道如何使用 react-select 很好地向 Select 添加类型。
到目前为止的组件看起来像这样:
const Select: React.FC<Select> = (
{defaultValue, onChange, options}: Select) => (
<ReactSelect
styles={selectStyles}
…
</ReactSelect>
Run Code Online (Sandbox Code Playgroud)
和的定义selectStyles:
interface HoverProps {
bowShadow: string
border: string
}
interface ControlComponentCSSProperties extends CSSProperties {
'&:hover': HoverProps
}
const selectStyles = {
control: (
provided: CSSProperties,
state: Props<{label: string; value: string}> | Props<Record<string, unknown>>
): ControlComponentCSSProperties => ({
...provided,
'&:hover': {
bowShadow: 'none',
border: 'none',
},
border: 'none',
borderRadius: input.border.radius,
borderBottomLeftRadius: state.menuIsOpen ? 0 : input.border.radius,
borderBottomRightRadius: state.menuIsOpen …Run Code Online (Sandbox Code Playgroud) react-select ×10
reactjs ×9
javascript ×2
ag-grid ×1
core-ui ×1
css ×1
focus ×1
font-awesome ×1
formik ×1
hover ×1
typescript ×1
yup ×1