仅使用文本搜索忽略ANTD SELECT组件中的表情符号

发布于 2025-02-12 07:54:09 字数 538 浏览 0 评论 0原文

我有ANTD的选择组件,其中选项标签不是文本。选项标签具有文字以及表情符号。现在,如果用户想搜索特定的文本,则选择组件将无法搜索具有表情符号的文本。

我想拥有的是用户应该搜索忽略表情符号的特定文本。

import React from 'react';
import 'antd/dist/antd.css';
import './index.css';
import { Select } from 'antd';
const { Option } = Select;

const App = () => (
  <Select
    showSearch
    style={{
      width: 200,
    }}
    placeholder="Search to Select"
    optionFilterProp="children"
    filterOption={(input, option) => option.children.includes(input)}
  >
    <Option value="1"><span>
              

I have select component of antd where option label is not text. Option label has text along with emoji. Now If user want to search for particular text, the select component is not able to search the text which has emojis.

What I want to have is User should search a particular text ignoring the emoji.

import React from 'react';
import 'antd/dist/antd.css';
import './index.css';
import { Select } from 'antd';
const { Option } = Select;

const App = () => (
  <Select
    showSearch
    style={{
      width: 200,
    }}
    placeholder="Search to Select"
    optionFilterProp="children"
    filterOption={(input, option) => option.children.includes(input)}
  >
    <Option value="1"><span>????</span> Not Identified</Option>
    <Option value="2"><span>????</span> Closed</Option>
    <Option value="3"><span>????</span> Communicated</Option>
    <Option value="4"><span>????</span> Identified</Option>
    <Option value="5"><span>????</span> Resolved</Option>
    <Option value="6"><span>????</span> Cancelled</Option>
  </Select>
);

export default App;

If need, I have a codesandbox link.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

假装不在乎 2025-02-19 07:54:09

这里只需使用tolowercase()字符串函数它的工作我刚刚更新了请检查 codesandbox链接

import React from "react";
import "antd/dist/antd.css";
import "./index.css";
import { Select } from "antd";
const { Option } = Select;

const onHandleSearch = (input, option) => {
let optionChildren = option.children.filter(
(item) => typeof item === "string"
);
return optionChildren[0].toLowerCase().includes(input.toLowerCase());
};

const App = () => (
<Select
showSearch
style={{
width: 200
}}
placeholder="Search to Select"
optionFilterProp="children"
filterOption={(input, option) => onHandleSearch(input, option)}
>
<Option value="1">
<span>

here just use toLowerCase() string function it's work i just updated pls check here codesandbox link

import React from "react";
import "antd/dist/antd.css";
import "./index.css";
import { Select } from "antd";
const { Option } = Select;

const onHandleSearch = (input, option) => {
  let optionChildren = option.children.filter(
    (item) => typeof item === "string"
  );
  return optionChildren[0].toLowerCase().includes(input.toLowerCase());
};

const App = () => (
  <Select
    showSearch
    style={{
      width: 200
    }}
    placeholder="Search to Select"
    optionFilterProp="children"
    filterOption={(input, option) => onHandleSearch(input, option)}
  >
    <Option value="1">
      <span>????</span> Not Identified
    </Option>
    <Option value="2">
      <span>????</span> Closed
    </Option>
    <Option value="3">
      <span>????</span> Communicated
    </Option>
    <Option value="4">
      <span>????</span> Identified
    </Option>
    <Option value="5">
      <span>????</span> Resolved
    </Option>
    <Option value="6">
      <span>????</span> Cancelled
    </Option>
  </Select>
);

export default App;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文