{"id":347474,"date":"2023-05-15T15:00:57","date_gmt":"2023-05-15T15:00:57","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=347474"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=347474","title":{"rendered":"<span>\u041a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 select \u0434\u043b\u044f React<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<p>\u041f\u0438\u0448\u0435\u043c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u0438\u0441\u0442\u0438\u0447\u043d\u044b\u0439 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 select \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0434\u043b\u044f React \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041f\u043e\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0432\u0441\u0451 \u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u043d\u0430 Jest.<\/p>\n<h3>\u041f\u043b\u0430\u043d \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439<\/h3>\n<p>\u041e\u0431\u0449\u0438\u0439 \u043f\u043b\u0430\u043d \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 5 \u044d\u0442\u0430\u043f\u043e\u0432:<\/p>\n<ol>\n<li>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0446\u0435\u043b\u044c<\/p>\n<\/li>\n<li>\n<p>\u041f\u0438\u0448\u0435\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 Select<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 Option<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0451 \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0442\u0435\u0441\u0442\u0430\u043c\u0438<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0441\u0442\u0430\u0440\u0442\u043e\u043c \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d css \u043a\u043e\u0434 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u043c\u0441\u044f \u043d\u0430 \u043b\u043e\u0433\u0438\u043a\u0435 \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0442\u0435\u0441\u0442\u043e\u0432. \u0412\u0441\u0435 \u0441\u0442\u0438\u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043f\u043e <a href=\"https:\/\/github.com\/robzarel\/gh-pages-demo\/blob\/article-examples\/src\/components\/select\/index.module.css\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0435<\/a>. \u0422\u0430\u043a\u0436\u0435 \u043f\u0440\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0438 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043a \u0440\u0430\u0437\u043d\u044b\u043c \u0446\u0432\u0435\u0442\u043e\u0432\u044b\u043c \u0442\u0435\u043c\u0430\u043c, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u044e \u043f\u0440\u043e <a href=\"https:\/\/habr.com\/ru\/articles\/732534\/\" rel=\"noopener noreferrer nofollow\">\u041f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0446\u0432\u0435\u0442\u043e\u0432\u044b\u0445 \u0442\u0435\u043c \u0432 React \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438<\/a>.<\/p>\n<p>\u041f\u043e\u0435\u0445\u0430\u043b\u0438!<\/p>\n<h3>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0446\u0435\u043b\u044c<\/h3>\n<p>\u041c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u0430\u043c\u043e\u043f\u0438\u0441\u043d\u044b\u0439 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u0441\u0435\u043b\u0435\u043a\u0442.<\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u043e\u0437\u044c\u043c\u0451\u043c\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u0441\u0435\u043b\u0435\u043a\u0442 \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u0430 \u043c\u0435\u0441\u044f\u0446\u0430. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u043f\u043e \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f\u043c \u0434\u0438\u0437\u0430\u0439\u043d\u0430, \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0443\u043c\u0435\u0442\u044c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c\u0441\u044f \u0432 \u0434\u0432\u0443\u0445 \u0440\u0435\u0436\u0438\u043c\u0430\u0445 &#8212; <strong>\u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0439<\/strong> (\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a) \u0438 <strong>\u043f\u043b\u0438\u0442\u043a\u043e\u0439<\/strong>(\u043f\u043e \u0442\u0440\u0438 \u043c\u0435\u0441\u044f\u0446\u0430 \u0432 \u0440\u044f\u0434).<\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0430\u0448 \u0441\u0435\u043b\u0435\u043a\u0442 \u0431\u0443\u0434\u0435\u0442 \u0447\u0430\u0441\u0442\u044c\u044e \u0444\u043e\u0440\u043c\u044b, \u043d\u0430\u043c \u0442\u0430\u043a \u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u0443\u0441\u0430 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u044f: <strong>\u043e\u0431\u044b\u0447\u043d\u044b\u0439<\/strong> \u0438\u043b\u0438 <strong>\u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439<\/strong>.<\/p>\n<p>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u0437 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 &#171;\u0441\u0432\u0435\u0440\u0445\u0443&#187;. \u0420\u043e\u0432\u043d\u043e \u043a\u0430\u043a \u0438 \u0441\u0430\u043c\u0438 \u043e\u043f\u0446\u0438\u0438 \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u0430. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0430\u043c \u043b\u0435\u0433\u043a\u043e \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442.<\/p>\n<p>\u041d\u0443 \u0438 \u0440\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043f\u0440\u043e\u043a\u0438\u043d\u0443\u0442\u044c \u043d\u0430\u0432\u0435\u0440\u0445 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043d\u0430\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0432\u044b\u0431\u043e\u0440\u0430 \u043e\u043f\u0446\u0438\u0438 \u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430.<\/p>\n<h3>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/h3>\n<p>\u041c\u0438\u043d\u0438\u043c\u0443\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439: \u0431\u0435\u0440\u0451\u043c <a href=\"https:\/\/create-react-app.dev\/\" rel=\"noopener noreferrer nofollow\">create-react-app<\/a> \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c typescript \u0438 \u0440\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435.<\/p>\n<pre><code class=\"bash\">  npx create-react-app my-app --template typescript <\/code><\/pre>\n<h3>\u041f\u0438\u0448\u0435\u043c \u0441\u0435\u043b\u0435\u043a\u0442<\/h3>\n<h4>\u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430<\/h4>\n<p>\u041f\u0435\u0440\u0435\u0432\u0435\u0434\u0451\u043c \u0432\u0441\u0435 \u043d\u0430\u0448\u0438 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430 typescript \u0438 \u043e\u043f\u0438\u0448\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0435\u043b\u0435\u043a\u0442\u0430:<\/p>\n<pre><code class=\"typescript\">type SelectProps = {   selected: Option | null;   options: Option[];   placeholder?: string;   mode?: 'rows' | 'cells';   status?: 'default' | 'invalid';   onChange?: (selected: Option['value']) =&gt; void;   onClose?: () =&gt; void; }; <\/code><\/pre>\n<p>\u0422\u0430\u043a \u0436\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043d\u0430\u0448\u0435\u0433\u043e \u0431\u0443\u0434\u0443\u0449\u0435\u0433\u043e option. \u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e &#8212; \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e 2 \u043f\u043e\u043b\u044f \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442:<\/p>\n<ul>\n<li>\n<p><strong>title<\/strong> \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p><strong>value<\/strong> \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0432 \u0444\u043e\u0440\u043c\u0435 \u043d\u0430 \u0431\u044d\u043a<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"typescript\">type Option = { title: string; value: string }; <\/code><\/pre>\n<h4>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f<\/h4>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0435\u043b\u0435\u043a\u0442\u0430 \u044d\u0442\u043e \u0441\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0438 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0442\u043e \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u043c\u0435\u0442\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430. \u0414\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0441\u0435\u043b\u0435\u043a\u0442\u0430 \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u0440\u0435\u0430\u043a\u0446\u0438\u0438 (\u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430 \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430) \u0437\u0430\u0432\u0435\u0434\u0451\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <strong>isOpen<\/strong>:<\/p>\n<pre><code class=\"typescript\">const [isOpen, setIsOpen] = useState(false); <\/code><\/pre>\n<p>\u0412 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u0431\u0443\u0434\u0435\u043c \u0435\u0451 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <a href=\"https:\/\/react.dev\/learn\/conditional-rendering\" rel=\"noopener noreferrer nofollow\">\u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0433\u043e \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430<\/a>.<\/p>\n<p>\u041b\u0443\u0447\u0448\u0438\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438 ui (\u0430 \u0442\u0430\u043a \u0436\u0435 \u0437\u0434\u0440\u0430\u0432\u044b\u0439 \u0441\u043c\u044b\u0441\u043b) \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442, \u0447\u0442\u043e \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044e <strong>hover<\/strong> (\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043d\u0430\u0441 \u0432\u043e\u0437\u043d\u0435\u043d\u0430\u0432\u0438\u0434\u044f\u0442 \u0437\u0430 \u0442\u0430\u043a\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435). \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u0434\u0440\u043e\u043f\u0434\u0430\u0443\u043d \u043f\u043e \u043a\u043b\u0438\u043a\u0443 <strong>\u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u043d\u0430\u0448\u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430<\/strong>.<br \/> \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 html \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043d\u0430\u0448 \u0441\u0435\u043b\u0435\u043a\u0442. \u0415\u0451 (\u0441\u0441\u044b\u043b\u043a\u0443) \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/react.dev\/reference\/react\/useRef\" rel=\"noopener noreferrer nofollow\">useRef<\/a>:<\/p>\n<pre><code class=\"typescript\">const rootRef = useRef&lt;HTMLDivElement&gt;(null); <\/code><\/pre>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 (\u043f\u0440\u0438 \u043a\u043b\u0438\u043a\u0435 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u043d\u0430\u0448\u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430) \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0444\u043b\u0430\u0433 <strong>isOpen<\/strong> \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 <strong>false<\/strong> \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c callback <strong>onClose<\/strong>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u043c \u0441\u043b\u0443\u0448\u0430\u0442\u044c \u0432\u0441\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f <strong>click<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0430 \u043d\u0430\u0448\u0435\u043c <strong>window<\/strong>, \u0430 \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435 <strong>handleClick<\/strong> \u0443\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0432\u044b\u0448\u0435\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443:<\/p>\n<pre><code class=\"typescript\">useEffect(() =&gt; {   const handleClick = (event: MouseEvent) =&gt; {     const { target } = event;     if (target instanceof Node &amp;&amp; !rootRef.current?.contains(target)) {       isOpen &amp;&amp; onClose?.();       setIsOpen(false);     }   };    window.addEventListener('click', handleClick); }, []); <\/code><\/pre>\n<p>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u0435 <strong>!rootRef.current?.contains(target)<\/strong> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043f\u043e\u043d\u044f\u0442\u044c \u043e\u0442\u043a\u0443\u0434\u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u0440\u0438\u0448\u043b\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043a\u043b\u0438\u043a\u0430. \u0410 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 <strong>target instanceof Node<\/strong> \u0434\u0435\u043b\u0430\u0435\u043c \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043d\u0435 \u0432\u0441\u0435 <strong>event.target<\/strong> \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438. <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/EventTarget\" rel=\"noopener noreferrer nofollow\">MDN.EventTarget<\/a>:<\/p>\n<blockquote>\n<p>Element, and its children, as well as Document and Window, are the most common event targets, but other objects can be event targets, too. For example XMLHttpRequest, AudioNode, and AudioContext are also event targets.<\/p>\n<\/blockquote>\n<p>\u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u0431\u044b \u043d\u0435 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c <strong>\u043f\u043e\u0434\u0432\u0438\u0441\u0448\u0438\u043c\u0438<\/strong> \u043d\u0430\u0448\u0438 \u0441\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043d\u0430 window, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u043a \u0443\u0442\u0435\u0447\u043a\u0430\u043c \u043f\u0430\u043c\u044f\u0442\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043d\u0430\u0434\u043e <strong>\u0432\u0435\u0440\u043d\u0443\u0442\u044c<\/strong> \u0438\u0437 useEffect \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u043e\u0442\u043f\u0438\u0448\u0435\u043c\u0441\u044f \u043e\u0442 \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f:<\/p>\n<pre><code class=\"typescript\">  useEffect(() =&gt; {     const handleClick = (event: MouseEvent) =&gt; {...};      window.addEventListener('click', handleClick);      return () =&gt; {       window.removeEventListener('click', handleClick);     };   }, []); <\/code><\/pre>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e \u0441\u0432\u044f\u0437\u044c \u0443\u0442\u0435\u0447\u0435\u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 \u044d\u0442\u043e\u0439 \u043d\u0435\u043f\u043b\u043e\u0445\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435: <a href=\"https:\/\/www.ditdot.hr\/en\/causes-of-memory-leaks-in-javascript-and-how-to-avoid-them#event-listeners\" rel=\"noopener noreferrer nofollow\">Causes of Memory Leaks in JavaScript and How to Avoid Them<\/a><\/p>\n<h4>\u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0451 \u0432\u043c\u0435\u0441\u0442\u0435<\/h4>\n<p>\u041a \u0442\u0435\u043a\u0443\u0449\u0435\u043c\u0443 \u043c\u043e\u043c\u0435\u043d\u0442\u0443 \u043d\u0430\u0448 \u0441\u0435\u043b\u0435\u043a\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"typescript\">type Option = { title: string; value: string }; type SelectProps = {   selected: Option | null;   options: Option[];   placeholder?: string;   mode?: 'rows' | 'cells';   status?: 'default' | 'invalid';   onChange?: (selected: Option['value']) =&gt; void;   onClose?: () =&gt; void; };  const Select = (props: SelectProps) =&gt; {   const { onClose } = props;   const [isOpen, setIsOpen] = useState(false);   const rootRef = useRef&lt;HTMLDivElement&gt;(null);    useEffect(() =&gt; {     const handleClick = (event: MouseEvent) =&gt; {       const { target } = event;       if (target instanceof Node &amp;&amp; !rootRef.current?.contains(target)) {         isOpen &amp;&amp; onClose?.();         setIsOpen(false);       }     };      window.addEventListener('click', handleClick);      return () =&gt; {       window.removeEventListener('click', handleClick);     };   }, [isOpen, onClose]);    return &lt;div ref={rootRef}&gt;...&lt;\/div&gt;; };  export default Select; <\/code><\/pre>\n<h4>\u0412\u0451\u0440\u0441\u0442\u043a\u0430<\/h4>\n<h3>\u041f\u043e\u0434\u0445\u043e\u0434 \u043a \u0441\u0442\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/h3>\n<p>\u0414\u043b\u044f \u0441\u0442\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/github.com\/css-modules\/css-modules\" rel=\"noopener noreferrer nofollow\">css modules<\/a> \u0434\u043b\u044f \u0441\u0442\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u0438 (\u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043b\u0435\u0436\u0438\u0442 react-create-app \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c typescript, \u0442\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 css modules \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438).<br \/> \u041d\u0430\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0438\u043b\u0438 \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c:<\/p>\n<pre><code class=\"typescript\">  import Styles from '.\/index.module.css';   ...    &lt;div className={Styles.selectWrapper} ref={rootRef}&gt;...&lt;\/div&gt; <\/code><\/pre>\n<h3>\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430<\/h3>\n<p>\u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0430\u043a \u0438\u043b\u0438 \u0438\u043d\u0430\u0447\u0435, \u0432\u043b\u0438\u044f\u044e\u0442 \u043d\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441\u0435\u043b\u0435\u043a\u0442\u0430.<br \/> \u041f\u0430\u0440\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0437\u0430 \u0441\u0447\u0451\u0442 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 <strong>status<\/strong>, \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043e\u0442 \u0440\u0435\u0436\u0438\u043c\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f <strong>mode<\/strong> \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f <strong>isOpen<\/strong>. \u041f\u043b\u044e\u0441 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u0441\u044f \u0435\u0449\u0451 2 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 &#171;\u0432\u044b\u0431\u0440\u0430\u043d\/\u043d\u0435 \u0432\u044b\u0431\u0440\u0430\u043d&#187; \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430. \u0421\u043f\u0438\u0441\u043e\u043a \u0431\u043e\u043b\u044c\u0448\u043e\u0439 (\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0435\u0449\u0451 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0438).<\/p>\n<p>\u0414\u043b\u044f \u0443\u0434\u043e\u0431\u043d\u043e\u0439 \u0441\u0442\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0441\u0435\u0445 \u044d\u0442\u0438\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong>data<\/strong> \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b. \u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e <strong>&#171;\u0440\u0435\u0436\u0438\u043c\u0430&#187;<\/strong> \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0441\u0435\u043b\u0435\u043a\u0442\u0430 <strong>&#171;\u043e\u0442\u043a\u0440\u044b\u0442\/\u0437\u0430\u043a\u0440\u044b\u0442&#187;<\/strong> \u0431\u0443\u0434\u0443\u0442 \u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u0441\u0442\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432\u0441\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b <strong>data-is-active<\/strong> \u0438 <strong>data-mode<\/strong> \u043d\u0430 \u0440\u0443\u0442\u043e\u0432\u043e\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430:<\/p>\n<pre><code class=\"typescript\">const Select = (props: SelectProps) =&gt; {   ...   return (     &lt;div       className={Styles.selectWrapper}       ref={rootRef}       data-is-active={isOpen}       data-mode={mode}     &gt;...&lt;\/div&gt;   ); } <\/code><\/pre>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0438\u043a\u043e\u043d\u043a\u0443 \u0441\u0442\u0440\u0435\u043b\u043e\u0447\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0448 \u0441\u0435\u043b\u0435\u043a\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b \u0431\u043e\u043b\u0435\u0435 &#171;\u043a\u0430\u043d\u043e\u043d\u0438\u0447\u043d\u043e&#187;:<\/p>\n<pre><code class=\"typescript\">import { ReactComponent as ArrowDown } from '.\/assets\/arrow-down.svg';  const Select = (props: SelectProps) =&gt; {   ...   return (     &lt;div       className={Styles.selectWrapper}       ref={rootRef}       data-is-active={isOpen}       data-mode={mode}     &gt;       &lt;div className={Styles.arrow}&gt;         &lt;ArrowDown \/&gt;       &lt;\/div&gt;       ...     &lt;\/div&gt;   ); } <\/code><\/pre>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442 svg \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0439, \u043d\u043e \u0447\u0442\u043e \u043f\u043e\u0434\u0435\u043b\u0430\u0442\u044c &#8212; \u0442\u0430\u043a\u043e\u0432\u044b \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f <a href=\"https:\/\/create-react-app.dev\/docs\/adding-images-fonts-and-files\/#adding-svgs\" rel=\"noopener noreferrer nofollow\">\u0438\u043c\u043f\u043e\u0440\u0442\u0430 svg<\/a> \u0432 create-react-app.<\/p>\n<p>\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u0443\u0441 \u0438 \u0432\u044b\u0431\u0440\u0430\u043d\/\u043d\u0435 \u0432\u044b\u0431\u0440\u0430\u043d&#187; \u0431\u0443\u0434\u0443\u0442 \u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u043e\u043b\u044f \u0432\u0432\u043e\u0434\u0430 (\u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u0430). \u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b <strong>data-status<\/strong> \u0438 <strong>data-selected<\/strong> \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a \u044d\u0442\u043e\u043c\u0443 \u0441\u0430\u043c\u043e\u043c\u0443 \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u0443:<\/p>\n<pre><code class=\"typescript\">const Select = (props: SelectProps) =&gt; {   ...   return (   &lt;div     className={Styles.selectWrapper}     ref={rootRef}     data-is-active={isOpen}     data-mode={mode}   &gt;     &lt;div className={Styles.arrow}&gt;       &lt;ArrowDown \/&gt;     &lt;\/div&gt;     &lt;div       className={Styles.placeholder}       data-status={status}       data-selected={!!selected?.value}     &gt;       {selected?.title || placeholder}     &lt;\/div&gt;     ...   &lt;\/div&gt;   ); } <\/code><\/pre>\n<h3>\u041e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430<\/h3>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0442\u044c \u0441\u0430\u043c \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043d\u0430 \u0432\u044b\u0431\u043e\u0440 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0441\u043f\u0438\u0441\u043a\u0430 \u0438 \u043a\u043b\u0438\u043a\u0430 \u043d\u0430 \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440.<\/p>\n<p>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0434\u043b\u044f \u043a\u043b\u0438\u043a\u0430 \u043f\u043e \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u0443 \u0431\u0443\u0434\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u043c &#8212; \u0435\u0433\u043e \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u043c\u0435\u043d\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0431\u0443\u043b\u0435\u0432\u043e\u0433\u043e \u0444\u043b\u0430\u0433\u0430 <strong>isOpen<\/strong> \u043d\u0430 \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u043f\u043e\u043b\u043e\u0436\u043d\u043e\u0435.<br \/> \u0422\u0430\u043a \u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u0442\u043e\u0440\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0431\u0443\u0434\u0443\u0449\u0438\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 . \u0414\u0435\u043b\u0430\u0442\u044c \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0442\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e \u0438 \u0445\u0435\u043d\u0434\u043b\u0435\u0440 \u0434\u043b\u044f \u043a\u043b\u0438\u043a\u0430 \u043f\u043e \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u0443, \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <strong>onChange<\/strong>.<\/p>\n<p>\u0412\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0431\u0443\u0434\u0435\u0442 \u0441\u043f\u0440\u044f\u0442\u0430\u043d \u0437\u0430 \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0439 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433.<\/p>\n<p>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0437\u0430\u0431\u0435\u0433\u0430\u044f \u0432\u043f\u0435\u0440\u0451\u0434, \u043e\u043f\u0438\u0448\u0435\u043c \u0442\u0430\u043a \u0436\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043d\u0430\u0448\u0435\u0433\u043e Option \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430:<\/p>\n<pre><code class=\"typescript\">type OptionProps = {   option: Option;   onClick: (value: Option['value']) =&gt; void; }; <\/code><\/pre>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 Select:<\/p>\n<pre><code class=\"typescript\">type SelectProps = {   selected: Option | null;   options: Option[];   placeholder?: string;   mode?: 'rows' | 'cells';   status?: 'default' | 'invalid';   onChange?: (selected: Option['value']) =&gt; void;   onClose?: () =&gt; void; };  const Select = (props: SelectProps) =&gt; {   const {     mode = 'rows',     options,     placeholder,     status = 'default',     selected,     onChange,     onClose,   } = props;   const [isOpen, setIsOpen] = useState&lt;boolean&gt;(false);   const rootRef = useRef&lt;HTMLDivElement&gt;(null);    useEffect(() =&gt; {     const handleClick = (event: MouseEvent) =&gt; {       const { target } = event;       if (target instanceof Node &amp;&amp; !rootRef.current?.contains(target)) {         isOpen &amp;&amp; onClose?.();         setIsOpen(false);       }     };      window.addEventListener('click', handleClick);      return () =&gt; {       window.removeEventListener('click', handleClick);     };   }, [isOpen, onClose]);    const handleOptionClick = (value: Option['value']) =&gt; {     setIsOpen(false);     onChange?.(value);   };   const handlePlaceHolderClick: MouseEventHandler&lt;HTMLDivElement&gt; = () =&gt; {     setIsOpen((prev) =&gt; !prev);   };    return (     &lt;div       className={Styles.selectWrapper}       ref={rootRef}       data-is-active={isOpen}       data-mode={mode}     &gt;       &lt;div className={Styles.arrow}&gt;         &lt;ArrowDown \/&gt;       &lt;\/div&gt;       &lt;div         className={Styles.placeholder}         data-status={status}         data-selected={!!selected?.value}         onClick={handlePlaceHolderClick}         role='button'         tabIndex={0}       &gt;         {selected?.title || placeholder}       &lt;\/div&gt;       {isOpen &amp;&amp; (         &lt;ul className={Styles.select}&gt;           {options.map((option) =&gt; (             &lt;Option               key={option.value}               option={option}               onClick={handleOptionClick}             \/&gt;           ))}         &lt;\/ul&gt;       )}     &lt;\/div&gt;   ); }; <\/code><\/pre>\n<p>PS: \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0430\u043c \u0432 \u044d\u0442\u043e\u043c \u043a\u0435\u0439\u0441\u0435 \u043d\u0435 \u043e\u0441\u043e\u0431\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c <strong>key<\/strong>, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043d\u0430\u0448\u0435\u0433\u043e \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u044b \u0438 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u043c\u0435\u043d\u044f\u0442\u044c \u0441\u0432\u043e\u0451 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435). \u041d\u043e \u0440\u0435\u0430\u043a\u0442 \u0432\u0435\u0436\u043b\u0438\u0432\u043e \u043f\u0440\u043e\u0441\u0438\u0442 \u043d\u0430\u0441 \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u043b\u044e\u0447\u0438, \u0447\u0442\u043e \u043c\u044b \u0438 \u0434\u0435\u043b\u0430\u0435\u043c. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435: <a href=\"https:\/\/react.dev\/learn\/rendering-lists#why-does-react-need-keys\" rel=\"noopener noreferrer nofollow\">why-does-react-need-keys<\/a>.<\/p>\n<h3>\u041f\u0438\u0448\u0435\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 Option<\/h3>\n<p>\u041c\u0438\u043d\u0438\u043c\u0430\u043b\u0438\u0441\u0442\u0438\u0447\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 &#171;\u043d\u0430\u0432\u0435\u0440\u0445&#187;.<\/p>\n<pre><code class=\"typescript\">type OptionProps = {   option: Option;   onClick: (value: Option['value']) =&gt; void; }; const Option = (props: OptionProps) =&gt; {   const {     option: { value, title },     onClick,   } = props;    const handleClick =     (clickedValue: Option['value']): MouseEventHandler&lt;HTMLLIElement&gt; =&gt;     () =&gt; {       onClick(clickedValue);     };    return (     &lt;li       className={Styles.option}       value={value}       onClick={handleClick(value)}       tabIndex={0}     &gt;       {title}     &lt;\/li&gt;   ); }; <\/code><\/pre>\n<h4>\u041a\u043e\u0434<\/h4>\n<p>\u0412\u0435\u0441\u044c \u043a\u043e\u0434 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u043e <a href=\"https:\/\/github.com\/robzarel\/gh-pages-demo\/blob\/article-examples\/src\/components\/select\/index.tsx\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0435<\/a><\/p>\n<h3>\u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0451 \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c<\/h3>\n<p>\u0414\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0441\u0435\u043b\u0435\u043a\u0442\u0430 \u0431\u0443\u0434\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435, \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c <strong>options.json<\/strong>:<\/p>\n<pre><code class=\"json\">[   { \"title\": \"\u044f\u043d\u0432\", \"value\": \"01\" },   { \"title\": \"\u0444\u0435\u0432\", \"value\": \"02\" },   { \"title\": \"\u043c\u0430\u0440\", \"value\": \"03\" },   { \"title\": \"\u0430\u043f\u0440\", \"value\": \"04\" },   { \"title\": \"\u043c\u0430\u0439\", \"value\": \"05\" },   { \"title\": \"\u0438\u044e\u043d\", \"value\": \"06\" },   { \"title\": \"\u0438\u044e\u043b\", \"value\": \"07\" },   { \"title\": \"\u0430\u0432\u0433\", \"value\": \"08\" },   { \"title\": \"\u0441\u0435\u043d\", \"value\": \"09\" },   { \"title\": \"\u043e\u043a\u0442\", \"value\": \"10\" },   { \"title\": \"\u043d\u043e\u044f\", \"value\": \"11\" },   { \"title\": \"\u0434\u0435\u043a\", \"value\": \"12\" } ] <\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u044d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b \u0432 \u043d\u0430\u0448 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043d\u0430\u0448\u0438\u043c \u043d\u043e\u0432\u044b\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c \u0438 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0451 \u0432\u043c\u0435\u0441\u0442\u0435:<\/p>\n<pre><code class=\"typescript\">import { useState } from 'react';  import options from '.\/components\/select\/options.json'; import Select from '.\/components\/select';  import '.\/App.css';  const App = () =&gt; {   const [month, setMonthValue] = useState('');   const handleMonthSelect = (value: string) =&gt; {     setMonthValue(value);   };    const selectedMonth = options.find((item) =&gt; item.value === month);    return (     &lt;div className='App'&gt;       &lt;div className='Select'&gt;         &lt;Select           mode='cells'           options={options}           selected={selectedMonth || null}           onChange={handleMonthSelect}           placeholder='\u0412\u044b\u0431\u0435\u0440\u0438\u0442\u0435 \u043c\u0435\u0441\u044f\u0446'         \/&gt;       &lt;\/div&gt;     &lt;\/div&gt;   ); };  export default App; <\/code><\/pre>\n<h3>\u041f\u0438\u0448\u0435\u043c \u0442\u0435\u0441\u0442\u044b<\/h3>\n<p>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u043c 3 \u0430\u0441\u043f\u0435\u043a\u0442\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430:<\/p>\n<ul>\n<li>\n<p>\u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432: <strong>data-selected<\/strong>, <strong>data-mode<\/strong>, <strong>data-status<\/strong> \u0438 <strong>data-is-active<\/strong><\/p>\n<\/li>\n<li>\n<p>\u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435\/\u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0437\u043e\u0432 \u043a\u043e\u043b\u043b\u0431\u044d\u043a\u043e\u0432<\/p>\n<\/li>\n<\/ul>\n<p>PS:<br \/> \u041f\u0435\u0440\u0435\u0434 \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043d\u0430\u043c data-testid \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b:<\/p>\n<ul>\n<li>\n<p>data-testid=&#187;selectWrapper&#187; \u0434\u043b\u044f \u043e\u0431\u0451\u0440\u0442\u043a\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430<\/p>\n<\/li>\n<li>\n<p>data-testid=&#187;selectDropdown&#187; \u0434\u043b\u044f \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430<\/p>\n<\/li>\n<li>\n<p>data-testid={<code>select-option-${value}<\/code>} \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e Option<\/p>\n<\/li>\n<\/ul>\n<p>\u041e\u043d\u0438 \u043d\u0443\u0436\u043d\u044b \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u0442\u0435\u0441\u0442\u0435 \u043d\u0430\u0448\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b.<\/p>\n<p>\u041f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043a\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e \u0442\u0435\u043a\u0441\u0442\u0443 \u0447\u0435\u0440\u0435\u0437 <strong>screen.getByText(&#8216;placeholder&#8217;)<\/strong><\/p>\n<p>\u041f\u0440\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0442\u0435\u0441\u0442\u0430 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u043c\u043e\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u043e <a href=\"https:\/\/habr.com\/ru\/articles\/734980\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u044e \u0432 React \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438<\/a> \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 <strong>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0442\u0435\u0441\u0442\u0430<\/strong>.<\/p>\n<p>\u041f\u043e\u0435\u0445\u0430\u043b\u0438!<\/p>\n<h4>\u041f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432<\/h4>\n<h3>\u0424\u0438\u043a\u0441\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 data-selected \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430.<\/h3>\n<pre><code class=\"javascript\">import '@testing-library\/jest-dom'; import { render, fireEvent, screen } from '@testing-library\/react';  import Select from '.\/index'; import options from '.\/options.json';  describe('React component: Select', () =&gt; {   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-selected=\"true\"] \u0434\u043b\u044f \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u0430, \u0435\u0441\u043b\u0438 \u0431\u044b\u043b\u043e \u0432\u044b\u0431\u0440\u0430\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435', async () =&gt; {     render(       &lt;Select         options={options}         onChange={jest.fn()}         selected={options[0]}         placeholder=\"placeholder\"       \/&gt;     );      const placeholder = screen.queryByText(options[0].title);     expect(placeholder).toHaveAttribute('data-selected', 'true');   });   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-selected=\"false\"] \u0434\u043b\u044f \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u0430, \u0435\u0441\u043b\u0438 \u041d\u0415 \u0431\u044b\u043b\u043e \u0432\u044b\u0431\u0440\u0430\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0435\u043b\u0435\u043a\u0442\u0430', async () =&gt; {     render(       &lt;Select         options={options}         onChange={jest.fn()}         selected={null}         placeholder=\"placeholder\"       \/&gt;     );      const placeholder = screen.queryByText('placeholder');      expect(placeholder).toHaveAttribute('data-selected', 'false');   }); } <\/code><\/pre>\n<h3>\u0424\u0438\u043a\u0441\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 data-mode \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430<\/h3>\n<pre><code class=\"javascript\">import '@testing-library\/jest-dom'; import { render, fireEvent, screen } from '@testing-library\/react';  import Select from '.\/index'; import options from '.\/options.json';  describe('React component: Select', () =&gt; {   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-selected=\"true\"] \u0434\u043b\u044f \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u0430, \u0435\u0441\u043b\u0438 \u0431\u044b\u043b\u043e \u0432\u044b\u0431\u0440\u0430\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435', async () =&gt; {...});   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-selected=\"false\"] \u0434\u043b\u044f \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u0430, \u0435\u0441\u043b\u0438 \u041d\u0415 \u0431\u044b\u043b\u043e \u0432\u044b\u0431\u0440\u0430\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0435\u043b\u0435\u043a\u0442\u0430', async () =&gt; {...});    it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-mode=\"rows\"] \u0434\u043b\u044f selectWrapper, \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 mode=rows', async () =&gt; {     render(       &lt;Select         options={options}         onChange={jest.fn()}         selected={null}         placeholder=\"placeholder\"         mode=\"rows\"       \/&gt;     );      const selectWrapper = screen.getByTestId('selectWrapper');     expect(selectWrapper).toHaveAttribute('data-mode', 'rows');   });   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-mode=\"cells\"] \u0434\u043b\u044f selectWrapper, \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 mode=cells', async () =&gt; {     render(       &lt;Select         options={options}         onChange={jest.fn()}         selected={null}         placeholder=\"placeholder\"         mode=\"cells\"       \/&gt;     );      const selectWrapper = screen.getByTestId('selectWrapper');     expect(selectWrapper).toHaveAttribute('data-mode', 'cells');   });   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-mode=\"rows\"] \u0434\u043b\u044f selectWrapper, \u0435\u0441\u043b\u0438 \u043d\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e mode \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043e', async () =&gt; {     render(       &lt;Select         options={options}         onChange={jest.fn()}         selected={null}         placeholder=\"placeholder\"       \/&gt;     );      const selectWrapper = screen.getByTestId('selectWrapper');     expect(selectWrapper).toHaveAttribute('data-mode', 'rows');   }); } <\/code><\/pre>\n<h3>\u0424\u0438\u043a\u0441\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 data-status \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430<\/h3>\n<pre><code class=\"javascript\">import '@testing-library\/jest-dom'; import { render, fireEvent, screen } from '@testing-library\/react';  import Select from '.\/index'; import options from '.\/options.json';  describe('React component: Select', () =&gt; {   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-selected=\"true\"] \u0434\u043b\u044f \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u0430, \u0435\u0441\u043b\u0438 \u0431\u044b\u043b\u043e \u0432\u044b\u0431\u0440\u0430\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435', async () =&gt; {...});   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-selected=\"false\"] \u0434\u043b\u044f \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u0430, \u0435\u0441\u043b\u0438 \u041d\u0415 \u0431\u044b\u043b\u043e \u0432\u044b\u0431\u0440\u0430\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0435\u043b\u0435\u043a\u0442\u0430', async () =&gt; {...});    it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-mode=\"rows\"] \u0434\u043b\u044f selectWrapper, \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 mode=rows', async () =&gt; {...});   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-mode=\"cells\"] \u0434\u043b\u044f selectWrapper, \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 mode=cells', async () =&gt; {...});   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-mode=\"rows\"] \u0434\u043b\u044f selectWrapper, \u0435\u0441\u043b\u0438 \u043d\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e mode \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043e', async () =&gt; {...});    it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-status=\"default\"] \u0434\u043b\u044f \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u0430, \u0435\u0441\u043b\u0438 \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u043a\u0438\u043d\u0443\u0442\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \"status: default\"', async () =&gt; {     render(       &lt;Select         options={options}         onChange={jest.fn()}         selected={null}         placeholder=\"placeholder\"       \/&gt;     );      const placeholder = screen.queryByText('placeholder');     expect(placeholder).toHaveAttribute('data-status', 'default');   });   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-status=\"invalid\"] \u0434\u043b\u044f \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u0430, \u0435\u0441\u043b\u0438 \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u043a\u0438\u043d\u0443\u0442\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \"status: invalid\"', async () =&gt; {     render(       &lt;Select         options={options}         onChange={jest.fn()}         selected={null}         placeholder=\"placeholder\"         status=\"invalid\"       \/&gt;     );      const placeholder = screen.queryByText('placeholder');     expect(placeholder).toHaveAttribute('data-status', 'invalid');   });   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-status=\"default\"] \u0434\u043b\u044f \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u0430, \u0435\u0441\u043b\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e status \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043e', async () =&gt; {     render(       &lt;Select         options={options}         onChange={jest.fn()}         selected={null}         placeholder=\"placeholder\"       \/&gt;     );      const placeholder = screen.queryByText('placeholder');     expect(placeholder).toHaveAttribute('data-status', 'default');   }); } <\/code><\/pre>\n<h3>\u0424\u0438\u043a\u0441\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 data-is-active \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430<\/h3>\n<pre><code class=\"javascript\">import '@testing-library\/jest-dom'; import { render, fireEvent, screen } from '@testing-library\/react';  import Select from '.\/index'; import options from '.\/options.json';  describe('React component: Select', () =&gt; {   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-selected=\"true\"] \u0434\u043b\u044f \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u0430, \u0435\u0441\u043b\u0438 \u0431\u044b\u043b\u043e \u0432\u044b\u0431\u0440\u0430\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435', async () =&gt; {...});   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-selected=\"false\"] \u0434\u043b\u044f \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u0430, \u0435\u0441\u043b\u0438 \u041d\u0415 \u0431\u044b\u043b\u043e \u0432\u044b\u0431\u0440\u0430\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0435\u043b\u0435\u043a\u0442\u0430', async () =&gt; {...});    it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-mode=\"rows\"] \u0434\u043b\u044f selectWrapper, \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 mode=rows', async () =&gt; {...});   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-mode=\"cells\"] \u0434\u043b\u044f selectWrapper, \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 mode=cells', async () =&gt; {...});   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-mode=\"rows\"] \u0434\u043b\u044f selectWrapper, \u0435\u0441\u043b\u0438 \u043d\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e mode \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043e', async () =&gt; {...});    it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-status=\"default\"] \u0434\u043b\u044f \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u0430, \u0435\u0441\u043b\u0438 \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u043a\u0438\u043d\u0443\u0442\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \"status: default\"', async () =&gt; {...});   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-status=\"invalid\"] \u0434\u043b\u044f \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u0430, \u0435\u0441\u043b\u0438 \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u043a\u0438\u043d\u0443\u0442\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \"status: invalid\"', async () =&gt; {...});   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-status=\"default\"] \u0434\u043b\u044f \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u0430, \u0435\u0441\u043b\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e status \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043e', async () =&gt; {...});    it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-is-active=\"true\"] \u0434\u043b\u044f selectWrapper, \u043f\u0440\u0438 \u043a\u043b\u0438\u043a\u0435 \u043d\u0430 \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440', async () =&gt; {     const handleSelect = jest.fn();      render(       &lt;Select         options={options}         onChange={handleSelect}         selected={null}         placeholder=\"placeholder\"         status=\"invalid\"       \/&gt;     );      const placeholder = screen.getByText('placeholder');     fireEvent.click(placeholder);      const selectWrapper = screen.getByTestId('selectWrapper');      expect(selectWrapper).toHaveAttribute('data-is-active', 'true');   });   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-is-active=\"false\"](\u043f\u0440\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u043c dropdown) \u0434\u043b\u044f selectWrapper, \u043f\u0440\u0438 \u043a\u043b\u0438\u043a\u0435 \u043d\u0430 \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440', async () =&gt; {     const handleSelect = jest.fn();      render(       &lt;Select         options={options}         onChange={handleSelect}         selected={null}         placeholder=\"placeholder\"         status=\"invalid\"       \/&gt;     );      const placeholder = screen.getByText('placeholder');     fireEvent.click(placeholder);     fireEvent.click(placeholder);      const selectWrapper = screen.getByTestId('selectWrapper');     expect(selectWrapper).toHaveAttribute('data-is-active', 'false');   }); } <\/code><\/pre>\n<h3>\u0424\u0438\u043a\u0441\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u044f\/\u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430<\/h3>\n<pre><code class=\"javascript\">import '@testing-library\/jest-dom'; import { render, fireEvent, screen } from '@testing-library\/react';  import Select from '.\/index'; import options from '.\/options.json';  describe('React component: Select', () =&gt; {   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-selected=\"true\"] \u0434\u043b\u044f \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u0430, \u0435\u0441\u043b\u0438 \u0431\u044b\u043b\u043e \u0432\u044b\u0431\u0440\u0430\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435', async () =&gt; {...});   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-selected=\"false\"] \u0434\u043b\u044f \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u0430, \u0435\u0441\u043b\u0438 \u041d\u0415 \u0431\u044b\u043b\u043e \u0432\u044b\u0431\u0440\u0430\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0435\u043b\u0435\u043a\u0442\u0430', async () =&gt; {...});    it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-mode=\"rows\"] \u0434\u043b\u044f selectWrapper, \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 mode=rows', async () =&gt; {...});   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-mode=\"cells\"] \u0434\u043b\u044f selectWrapper, \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 mode=cells', async () =&gt; {...});   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-mode=\"rows\"] \u0434\u043b\u044f selectWrapper, \u0435\u0441\u043b\u0438 \u043d\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e mode \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043e', async () =&gt; {...});    it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-status=\"default\"] \u0434\u043b\u044f \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u0430, \u0435\u0441\u043b\u0438 \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u043a\u0438\u043d\u0443\u0442\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \"status: default\"', async () =&gt; {...});   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-status=\"invalid\"] \u0434\u043b\u044f \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u0430, \u0435\u0441\u043b\u0438 \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u043a\u0438\u043d\u0443\u0442\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \"status: invalid\"', async () =&gt; {...});   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-status=\"default\"] \u0434\u043b\u044f \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u0430, \u0435\u0441\u043b\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e status \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043e', async () =&gt; {...});    it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-is-active=\"true\"] \u0434\u043b\u044f selectWrapper, \u043f\u0440\u0438 \u043a\u043b\u0438\u043a\u0435 \u043d\u0430 \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440', async () =&gt; {...});   it('\u0414\u043e\u043b\u0436\u0435\u043d \u043f\u0440\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [data-is-active=\"false\"](\u043f\u0440\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u043c dropdown) \u0434\u043b\u044f selectWrapper, \u043f\u0440\u0438 \u043a\u043b\u0438\u043a\u0435 \u043d\u0430 \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440', async () =&gt; {...});    it('\u041f\u043e \u043a\u043b\u0438\u043a\u0443 \u043d\u0430 \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c\u0441\u044f dropdown', async () =&gt; {     const handleSelect = jest.fn();      render(       &lt;Select         options={options}         onChange={handleSelect}         selected={null}         placeholder=\"placeholder\"         status=\"invalid\"       \/&gt;     );      const placeholder = screen.getByText('placeholder');     fireEvent.click(placeholder);      const selectDropdown = screen.getByTestId('selectDropdown');     expect(selectDropdown).toBeInTheDocument();   });   it('\u041f\u043e \u043a\u043b\u0438\u043a\u0443 \u043d\u0430 \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440 (\u043f\u0440\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u043c dropdown) \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0442\u044c\u0441\u044f dropdown', async () =&gt; {     const handleSelect = jest.fn();      render(       &lt;Select         options={options}         onChange={handleSelect}         selected={null}         placeholder=\"placeholder\"         status=\"invalid\"       \/&gt;     );      const placeholder = screen.getByText('placeholder');     fireEvent.click(placeholder);     fireEvent.click(placeholder);      const selectDropdown = screen.queryByTestId('selectDropdown');     expect(selectDropdown).not.toBeInTheDocument();   });   it('\u041f\u043e \u043a\u043b\u0438\u043a\u0443 \u043d\u0430 option \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \"onChange\" \u0438 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0442\u044c\u0441\u044f dropdown', async () =&gt; {     const handleSelect = jest.fn();      render(       &lt;Select         options={options}         onChange={handleSelect}         selected={null}         placeholder=\"placeholder\"         status=\"invalid\"       \/&gt;     );      const placeholder = screen.getByText('placeholder');     fireEvent.click(placeholder);      const option = screen.getByText(options[0].title);     fireEvent.click(option);      const optionAfterClick = screen.queryByText(options[0].title);      expect(optionAfterClick).not.toBeInTheDocument();     expect(handleSelect).toHaveBeenCalledTimes(1);   });   it('\u041f\u043e \u043a\u043b\u0438\u043a\u0443 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u043c\u0438 \u0441\u0435\u043b\u0435\u043a\u0442\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \"onClose\" \u0438 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0442\u044c\u0441\u044f dropdown', async () =&gt; {     const handleClose = jest.fn();      render(       &lt;div&gt;         &lt;div data-testid=\"1\"&gt;outer element&lt;\/div&gt;         &lt;Select           options={options}           onChange={jest.fn()}           onClose={handleClose}           selected={null}           placeholder=\"placeholder\"           status=\"invalid\"         \/&gt;       &lt;\/div&gt;     );      const placeholder = screen.getByText('placeholder');     fireEvent.click(placeholder);      const outerElement = screen.getByTestId('1');     fireEvent.click(outerElement);      const option = screen.queryByText(options[0].title);      expect(option).not.toBeInTheDocument();     expect(handleClose).toHaveBeenCalledTimes(1);   }); } <\/code><\/pre>\n<p>\u0422\u0435\u0441\u0442\u043e\u0432 \u0445\u043e\u0442\u044c \u0438 \u043c\u043d\u043e\u0433\u043e, \u043d\u043e \u043e\u043d\u0438 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0438 \u0434\u0440\u0443\u0433 \u043d\u0430 \u0434\u0440\u0443\u0433\u0430 \u0438 \u043f\u0438\u0448\u0443\u0442\u0441\u044f \u0431\u044b\u0441\u0442\u0440\u043e).<br \/> \u0412\u0441\u0435 \u0442\u0435\u0441\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u043f\u043e <a href=\"https:\/\/github.com\/robzarel\/gh-pages-demo\/blob\/article-examples\/src\/components\/select\/select.test.tsx\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0435<\/a>.<\/p>\n<h3>\u0418\u0442\u043e\u0433\u043e<\/h3>\n<p>\u041c\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u044b\u0439 \u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043d\u0430\u0434\u0451\u0436\u043d\u044b\u0439 (\u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u043f\u0430\u0447\u043a\u0435 \u0442\u0435\u0441\u0442\u043e\u0432) \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u0441\u0435\u043b\u0435\u043a\u0442.<\/p>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0447\u0442\u0435\u043d\u0438\u0435 \u0438 \u0443\u0434\u0430\u0447\u0438 \u0432 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0432\u0430\u0448\u0438\u0445 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432)<\/p>\n<p>PS: \u0421\u0441\u044b\u043b\u043a\u0438 \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438:<\/p>\n<ul>\n<li>\n<p>\u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 <a href=\"https:\/\/github.com\/robzarel\/gh-pages-demo\/tree\/article-examples\/src\/components\/select\" rel=\"noopener noreferrer nofollow\">Select<\/a><\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e <a href=\"https:\/\/create-react-app.dev\/\" rel=\"noopener noreferrer nofollow\">create-react-app<\/a><\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e <a href=\"https:\/\/create-react-app.dev\/docs\/adding-images-fonts-and-files\/#adding-svgs\" rel=\"noopener noreferrer nofollow\">\u0438\u043c\u043f\u043e\u0440\u0442 svg<\/a> \u0432 create-react-app<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e <a href=\"https:\/\/github.com\/css-modules\/css-modules\" rel=\"noopener noreferrer nofollow\">css modules<\/a><\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e <a href=\"https:\/\/react.dev\/learn\/conditional-rendering\" rel=\"noopener noreferrer nofollow\">\u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0439 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433<\/a><\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e <a href=\"https:\/\/testing-library.com\/docs\/react-testing-library\/example-intro\" rel=\"noopener noreferrer nofollow\">@testing-library\/react<\/a><\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e <a href=\"https:\/\/react.dev\/reference\/react\/useEffect\" rel=\"noopener noreferrer nofollow\">useEffect<\/a>, <a href=\"https:\/\/react.dev\/reference\/react\/useState\" rel=\"noopener noreferrer nofollow\">useState<\/a> \u0438 <a href=\"https:\/\/react.dev\/reference\/react\/useRef\" rel=\"noopener noreferrer nofollow\">useRef<\/a><\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e <a href=\"https:\/\/react.dev\/reference\/react\/memo\" rel=\"noopener noreferrer nofollow\">React.memo<\/a><\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e <a href=\"https:\/\/www.ditdot.hr\/en\/causes-of-memory-leaks-in-javascript-and-how-to-avoid-them#event-listeners\" rel=\"noopener noreferrer nofollow\">\u0443\u0442\u0435\u0447\u043a\u0438 \u043f\u0430\u043c\u044f\u0442\u0438<\/a><\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e <a href=\"https:\/\/habr.com\/ru\/articles\/732534\/\" rel=\"noopener noreferrer nofollow\">\u041f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0446\u0432\u0435\u0442\u043e\u0432\u044b\u0445 \u0442\u0435\u043c \u0432 React \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438<\/a><\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e <a href=\"https:\/\/habr.com\/ru\/articles\/734980\/\" rel=\"noopener noreferrer nofollow\">\u041f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u044e \u0432 React \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/735224\/\"> https:\/\/habr.com\/ru\/articles\/735224\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<p>\u041f\u0438\u0448\u0435\u043c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u0438\u0441\u0442\u0438\u0447\u043d\u044b\u0439 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 select \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0434\u043b\u044f React \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041f\u043e\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0432\u0441\u0451 \u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u043d\u0430 Jest.<\/p>\n<h3>\u041f\u043b\u0430\u043d \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439<\/h3>\n<p>\u041e\u0431\u0449\u0438\u0439 \u043f\u043b\u0430\u043d \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 5 \u044d\u0442\u0430\u043f\u043e\u0432:<\/p>\n<ol>\n<li>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0446\u0435\u043b\u044c<\/p>\n<\/li>\n<li>\n<p>\u041f\u0438\u0448\u0435\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 Select<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 Option<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0451 \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0442\u0435\u0441\u0442\u0430\u043c\u0438<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0441\u0442\u0430\u0440\u0442\u043e\u043c \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d css \u043a\u043e\u0434 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0441\u043e\u0441\u0440\u0435\u0434\u043e\u0442\u043e\u0447\u0438\u043c\u0441\u044f \u043d\u0430 \u043b\u043e\u0433\u0438\u043a\u0435 \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0442\u0435\u0441\u0442\u043e\u0432. \u0412\u0441\u0435 \u0441\u0442\u0438\u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u043f\u043e <a href=\"https:\/\/github.com\/robzarel\/gh-pages-demo\/blob\/article-examples\/src\/components\/select\/index.module.css\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0435<\/a>. \u0422\u0430\u043a\u0436\u0435 \u043f\u0440\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0438 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043a \u0440\u0430\u0437\u043d\u044b\u043c \u0446\u0432\u0435\u0442\u043e\u0432\u044b\u043c \u0442\u0435\u043c\u0430\u043c, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u044e \u043f\u0440\u043e <a href=\"https:\/\/habr.com\/ru\/articles\/732534\/\" rel=\"noopener noreferrer nofollow\">\u041f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0446\u0432\u0435\u0442\u043e\u0432\u044b\u0445 \u0442\u0435\u043c \u0432 React \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438<\/a>.<\/p>\n<p>\u041f\u043e\u0435\u0445\u0430\u043b\u0438!<\/p>\n<h3>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0446\u0435\u043b\u044c<\/h3>\n<p>\u041c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u0430\u043c\u043e\u043f\u0438\u0441\u043d\u044b\u0439 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u0441\u0435\u043b\u0435\u043a\u0442.<\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u043e\u0437\u044c\u043c\u0451\u043c\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u0441\u0435\u043b\u0435\u043a\u0442 \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u0430 \u043c\u0435\u0441\u044f\u0446\u0430. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u043f\u043e \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f\u043c \u0434\u0438\u0437\u0430\u0439\u043d\u0430, \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0443\u043c\u0435\u0442\u044c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c\u0441\u044f \u0432 \u0434\u0432\u0443\u0445 \u0440\u0435\u0436\u0438\u043c\u0430\u0445 &#8212; <strong>\u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0439<\/strong> (\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a) \u0438 <strong>\u043f\u043b\u0438\u0442\u043a\u043e\u0439<\/strong>(\u043f\u043e \u0442\u0440\u0438 \u043c\u0435\u0441\u044f\u0446\u0430 \u0432 \u0440\u044f\u0434).<\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0430\u0448 \u0441\u0435\u043b\u0435\u043a\u0442 \u0431\u0443\u0434\u0435\u0442 \u0447\u0430\u0441\u0442\u044c\u044e \u0444\u043e\u0440\u043c\u044b, \u043d\u0430\u043c \u0442\u0430\u043a \u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u0443\u0441\u0430 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u044f: <strong>\u043e\u0431\u044b\u0447\u043d\u044b\u0439<\/strong> \u0438\u043b\u0438 <strong>\u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439<\/strong>.<\/p>\n<p>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u0437 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 &#171;\u0441\u0432\u0435\u0440\u0445\u0443&#187;. \u0420\u043e\u0432\u043d\u043e \u043a\u0430\u043a \u0438 \u0441\u0430\u043c\u0438 \u043e\u043f\u0446\u0438\u0438 \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u0430. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0430\u043c \u043b\u0435\u0433\u043a\u043e \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442.<\/p>\n<p>\u041d\u0443 \u0438 \u0440\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043f\u0440\u043e\u043a\u0438\u043d\u0443\u0442\u044c \u043d\u0430\u0432\u0435\u0440\u0445 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043d\u0430\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0432\u044b\u0431\u043e\u0440\u0430 \u043e\u043f\u0446\u0438\u0438 \u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430.<\/p>\n<h3>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/h3>\n<p>\u041c\u0438\u043d\u0438\u043c\u0443\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439: \u0431\u0435\u0440\u0451\u043c <a href=\"https:\/\/create-react-app.dev\/\" rel=\"noopener noreferrer nofollow\">create-react-app<\/a> \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c typescript \u0438 \u0440\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435.<\/p>\n<pre><code class=\"bash\">  npx create-react-app my-app --template typescript <\/code><\/pre>\n<h3>\u041f\u0438\u0448\u0435\u043c \u0441\u0435\u043b\u0435\u043a\u0442<\/h3>\n<h4>\u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430<\/h4>\n<p>\u041f\u0435\u0440\u0435\u0432\u0435\u0434\u0451\u043c \u0432\u0441\u0435 \u043d\u0430\u0448\u0438 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430 typescript \u0438 \u043e\u043f\u0438\u0448\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0435\u043b\u0435\u043a\u0442\u0430:<\/p>\n<pre><code class=\"typescript\">type SelectProps = {   selected: Option | null;   options: Option[];   placeholder?: string;   mode?: 'rows' | 'cells';   status?: 'default' | 'invalid';   onChange?: (selected: Option['value']) =&gt; void;   onClose?: () =&gt; void; }; <\/code><\/pre>\n<p>\u0422\u0430\u043a \u0436\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043d\u0430\u0448\u0435\u0433\u043e \u0431\u0443\u0434\u0443\u0449\u0435\u0433\u043e option. \u0417\u0434\u0435\u0441\u044c \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e &#8212; \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e 2 \u043f\u043e\u043b\u044f \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442:<\/p>\n<ul>\n<li>\n<p><strong>title<\/strong> \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p><strong>value<\/strong> \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0432 \u0444\u043e\u0440\u043c\u0435 \u043d\u0430 \u0431\u044d\u043a<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"typescript\">type Option = { title: string; value: string }; <\/code><\/pre>\n<h4>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f<\/h4>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0435\u043b\u0435\u043a\u0442\u0430 \u044d\u0442\u043e \u0441\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0438 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0442\u043e \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u043c\u0435\u0442\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430. \u0414\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0441\u0435\u043b\u0435\u043a\u0442\u0430 \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u0440\u0435\u0430\u043a\u0446\u0438\u0438 (\u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430 \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430) \u0437\u0430\u0432\u0435\u0434\u0451\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <strong>isOpen<\/strong>:<\/p>\n<pre><code class=\"typescript\">const [isOpen, setIsOpen] = useState(false); <\/code><\/pre>\n<p>\u0412 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u0431\u0443\u0434\u0435\u043c \u0435\u0451 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <a href=\"https:\/\/react.dev\/learn\/conditional-rendering\" rel=\"noopener noreferrer nofollow\">\u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0433\u043e \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0430<\/a>.<\/p>\n<p>\u041b\u0443\u0447\u0448\u0438\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438 ui (\u0430 \u0442\u0430\u043a \u0436\u0435 \u0437\u0434\u0440\u0430\u0432\u044b\u0439 \u0441\u043c\u044b\u0441\u043b) \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442, \u0447\u0442\u043e \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044e <strong>hover<\/strong> (\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043d\u0430\u0441 \u0432\u043e\u0437\u043d\u0435\u043d\u0430\u0432\u0438\u0434\u044f\u0442 \u0437\u0430 \u0442\u0430\u043a\u043e\u0435 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435). \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u0434\u0440\u043e\u043f\u0434\u0430\u0443\u043d \u043f\u043e \u043a\u043b\u0438\u043a\u0443 <strong>\u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u043d\u0430\u0448\u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430<\/strong>.<br \/> \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 html \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043d\u0430\u0448 \u0441\u0435\u043b\u0435\u043a\u0442. \u0415\u0451 (\u0441\u0441\u044b\u043b\u043a\u0443) \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <a href=\"https:\/\/react.dev\/reference\/react\/useRef\" rel=\"noopener noreferrer nofollow\">useRef<\/a>:<\/p>\n<pre><code class=\"typescript\">const rootRef = useRef&lt;HTMLDivElement&gt;(null); <\/code><\/pre>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 (\u043f\u0440\u0438 \u043a\u043b\u0438\u043a\u0435 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u043d\u0430\u0448\u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430) \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0444\u043b\u0430\u0433 <strong>isOpen<\/strong> \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 <strong>false<\/strong> \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c callback <strong>onClose<\/strong>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u043c \u0441\u043b\u0443\u0448\u0430\u0442\u044c \u0432\u0441\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f <strong>click<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0430 \u043d\u0430\u0448\u0435\u043c <strong>window<\/strong>, \u0430 \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435 <strong>handleClick<\/strong> \u0443\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0432\u044b\u0448\u0435\u043e\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443:<\/p>\n<pre><code class=\"typescript\">useEffect(() =&gt; {   const handleClick = (event: MouseEvent) =&gt; {     const { target } = event;     if (target instanceof Node &amp;&amp; !rootRef.current?.contains(target)) {       isOpen &amp;&amp; onClose?.();       setIsOpen(false);     }   };    window.addEventListener('click', handleClick); }, []); <\/code><\/pre>\n<p>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u0435 <strong>!rootRef.current?.contains(target)<\/strong> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043f\u043e\u043d\u044f\u0442\u044c \u043e\u0442\u043a\u0443\u0434\u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u0440\u0438\u0448\u043b\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043a\u043b\u0438\u043a\u0430. \u0410 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 <strong>target instanceof Node<\/strong> \u0434\u0435\u043b\u0430\u0435\u043c \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043d\u0435 \u0432\u0441\u0435 <strong>event.target<\/strong> \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438. <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/EventTarget\" rel=\"noopener noreferrer nofollow\">MDN.EventTarget<\/a>:<\/p>\n<blockquote>\n<p>Element, and its children, as well as Document and Window, are the most common event targets, but other objects can be event targets, too. For example XMLHttpRequest, AudioNode, and AudioContext are also event targets.<\/p>\n<\/blockquote>\n<p>\u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u0431\u044b \u043d\u0435 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c <strong>\u043f\u043e\u0434\u0432\u0438\u0441\u0448\u0438\u043c\u0438<\/strong> \u043d\u0430\u0448\u0438 \u0441\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043d\u0430 window, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u043a \u0443\u0442\u0435\u0447\u043a\u0430\u043c \u043f\u0430\u043c\u044f\u0442\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043d\u0430\u0434\u043e <strong>\u0432\u0435\u0440\u043d\u0443\u0442\u044c<\/strong> \u0438\u0437 useEffect \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u043e\u0442\u043f\u0438\u0448\u0435\u043c\u0441\u044f \u043e\u0442 \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f:<\/p>\n<pre><code class=\"typescript\">  useEffect(() =&gt; {     const handleClick = (event: MouseEvent) =&gt; {...};      window.addEventListener('click', handleClick);      return () =&gt; {       window.removeEventListener('click', handleClick);     };   }, []); <\/code><\/pre>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e \u0441\u0432\u044f\u0437\u044c \u0443\u0442\u0435\u0447\u0435\u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432 \u044d\u0442\u043e\u0439 \u043d\u0435\u043f\u043b\u043e\u0445\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435: <a href=\"https:\/\/www.ditdot.hr\/en\/causes-of-memory-leaks-in-javascript-and-how-to-avoid-them#event-listeners\" rel=\"noopener noreferrer nofollow\">Causes of Memory Leaks in JavaScript and How to Avoid Them<\/a><\/p>\n<h4>\u0421\u043e\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0451 \u0432\u043c\u0435\u0441\u0442\u0435<\/h4>\n<p>\u041a \u0442\u0435\u043a\u0443\u0449\u0435\u043c\u0443 \u043c\u043e\u043c\u0435\u043d\u0442\u0443 \u043d\u0430\u0448 \u0441\u0435\u043b\u0435\u043a\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"typescript\">type Option = { title: string; value: string }; type SelectProps = {   selected: Option | null;   options: Option[];   placeholder?: string;   mode?: 'rows' | 'cells';   status?: 'default' | 'invalid';   onChange?: (selected: Option['value']) =&gt; void;   onClose?: () =&gt; void; };  const Select = (props: SelectProps) =&gt; {   const { onClose } = props;   const [isOpen, setIsOpen] = useState(false);   const rootRef = useRef&lt;HTMLDivElement&gt;(null);    useEffect(() =&gt; {     const handleClick = (event: MouseEvent) =&gt; {       const { target } = event;       if (target instanceof Node &amp;&amp; !rootRef.current?.contains(target)) {         isOpen &amp;&amp; onClose?.();         setIsOpen(false);       }     };      window.addEventListener('click', handleClick);      return () =&gt; {       window.removeEventListener('click', handleClick);     };   }, [isOpen, onClose]);    return &lt;div ref={rootRef}&gt;...&lt;\/div&gt;; };  export default Select; <\/code><\/pre>\n<h4>\u0412\u0451\u0440\u0441\u0442\u043a\u0430<\/h4>\n<h3>\u041f\u043e\u0434\u0445\u043e\u0434 \u043a \u0441\u0442\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u0438<\/h3>\n<p>\u0414\u043b\u044f \u0441\u0442\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/github.com\/css-modules\/css-modules\" rel=\"noopener noreferrer nofollow\">css modules<\/a> \u0434\u043b\u044f \u0441\u0442\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u0438 (\u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043b\u0435\u0436\u0438\u0442 react-create-app \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c typescript, \u0442\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 css modules \u0443 \u043d\u0430\u0441 \u0443\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438).<br \/> \u041d\u0430\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0438\u043b\u0438 \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c:<\/p>\n<pre><code class=\"typescript\">  import Styles from '.\/index.module.css';   ...    &lt;div className={Styles.selectWrapper} ref={rootRef}&gt;...&lt;\/div&gt; <\/code><\/pre>\n<h3>\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430<\/h3>\n<p>\u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0430\u043a \u0438\u043b\u0438 \u0438\u043d\u0430\u0447\u0435, \u0432\u043b\u0438\u044f\u044e\u0442 \u043d\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441\u0435\u043b\u0435\u043a\u0442\u0430.<br \/> \u041f\u0430\u0440\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0437\u0430 \u0441\u0447\u0451\u0442 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 <strong>status<\/strong>, \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043e\u0442 \u0440\u0435\u0436\u0438\u043c\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f <strong>mode<\/strong> \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f <strong>isOpen<\/strong>. \u041f\u043b\u044e\u0441 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u0441\u044f \u0435\u0449\u0451 2 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 &#171;\u0432\u044b\u0431\u0440\u0430\u043d\/\u043d\u0435 \u0432\u044b\u0431\u0440\u0430\u043d&#187; \u043a\u0430\u043a\u043e\u0439-\u043b\u0438\u0431\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438\u0437 \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430. \u0421\u043f\u0438\u0441\u043e\u043a \u0431\u043e\u043b\u044c\u0448\u043e\u0439 (\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0435\u0449\u0451 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0438).<\/p>\n<p>\u0414\u043b\u044f \u0443\u0434\u043e\u0431\u043d\u043e\u0439 \u0441\u0442\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0441\u0435\u0445 \u044d\u0442\u0438\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <strong>data<\/strong> \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b. \u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e <strong>&#171;\u0440\u0435\u0436\u0438\u043c\u0430&#187;<\/strong> \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0441\u0435\u043b\u0435\u043a\u0442\u0430 <strong>&#171;\u043e\u0442\u043a\u0440\u044b\u0442\/\u0437\u0430\u043a\u0440\u044b\u0442&#187;<\/strong> \u0431\u0443\u0434\u0443\u0442 \u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u0441\u0442\u0438\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432\u0441\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b <strong>data-is-active<\/strong> \u0438 <strong>data-mode<\/strong> \u043d\u0430 \u0440\u0443\u0442\u043e\u0432\u043e\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430:<\/p>\n<pre><code class=\"typescript\">const Select = (props: SelectProps) =&gt; {   ...   return (     &lt;div       className={Styles.selectWrapper}       ref={rootRef}       data-is-active={isOpen}       data-mode={mode}     &gt;...&lt;\/div&gt;   ); } <\/code><\/pre>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0438\u043a\u043e\u043d\u043a\u0443 \u0441\u0442\u0440\u0435\u043b\u043e\u0447\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0448 \u0441\u0435\u043b\u0435\u043a\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b \u0431\u043e\u043b\u0435\u0435 &#171;\u043a\u0430\u043d\u043e\u043d\u0438\u0447\u043d\u043e&#187;:<\/p>\n<pre><code class=\"typescript\">import { ReactComponent as ArrowDown } from '.\/assets\/arrow-down.svg';  const Select = (props: SelectProps) =&gt; {   ...   return (     &lt;div       className={Styles.selectWrapper}       ref={rootRef}       data-is-active={isOpen}       data-mode={mode}     &gt;       &lt;div className={Styles.arrow}&gt;         &lt;ArrowDown \/&gt;       &lt;\/div&gt;       ...     &lt;\/div&gt;   ); } <\/code><\/pre>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442 svg \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0439, \u043d\u043e \u0447\u0442\u043e \u043f\u043e\u0434\u0435\u043b\u0430\u0442\u044c &#8212; \u0442\u0430\u043a\u043e\u0432\u044b \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f <a href=\"https:\/\/create-react-app.dev\/docs\/adding-images-fonts-and-files\/#adding-svgs\" rel=\"noopener noreferrer nofollow\">\u0438\u043c\u043f\u043e\u0440\u0442\u0430 svg<\/a> \u0432 create-react-app.<\/p>\n<p>\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u0443\u0441 \u0438 \u0432\u044b\u0431\u0440\u0430\u043d\/\u043d\u0435 \u0432\u044b\u0431\u0440\u0430\u043d&#187; \u0431\u0443\u0434\u0443\u0442 \u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u043e\u043b\u044f \u0432\u0432\u043e\u0434\u0430 (\u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u0430). \u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b <strong>data-status<\/strong> \u0438 <strong>data-selected<\/strong> \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a \u044d\u0442\u043e\u043c\u0443 \u0441\u0430\u043c\u043e\u043c\u0443 \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u0443:<\/p>\n<pre><code class=\"typescript\">const Select = (props: SelectProps) =&gt; {   ...   return (   &lt;div     className={Styles.selectWrapper}     ref={rootRef}     data-is-active={isOpen}     data-mode={mode}   &gt;     &lt;div className={Styles.arrow}&gt;       &lt;ArrowDown \/&gt;     &lt;\/div&gt;     &lt;div       className={Styles.placeholder}       data-status={status}       data-selected={!!selected?.value}     &gt;       {selected?.title || placeholder}     &lt;\/div&gt;     ...   &lt;\/div&gt;   ); } <\/code><\/pre>\n<h3>\u041e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430<\/h3>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0442\u044c \u0441\u0430\u043c \u0432\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043d\u0430 \u0432\u044b\u0431\u043e\u0440 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0441\u043f\u0438\u0441\u043a\u0430 \u0438 \u043a\u043b\u0438\u043a\u0430 \u043d\u0430 \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440.<\/p>\n<p>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0434\u043b\u044f \u043a\u043b\u0438\u043a\u0430 \u043f\u043e \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u0443 \u0431\u0443\u0434\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u043c &#8212; \u0435\u0433\u043e \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u043c\u0435\u043d\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0431\u0443\u043b\u0435\u0432\u043e\u0433\u043e \u0444\u043b\u0430\u0433\u0430 <strong>isOpen<\/strong> \u043d\u0430 \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u043f\u043e\u043b\u043e\u0436\u043d\u043e\u0435.<br \/> \u0422\u0430\u043a \u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u0442\u043e\u0440\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0431\u0443\u0434\u0443\u0449\u0438\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 . \u0414\u0435\u043b\u0430\u0442\u044c \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0442\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0447\u0442\u043e \u0438 \u0445\u0435\u043d\u0434\u043b\u0435\u0440 \u0434\u043b\u044f \u043a\u043b\u0438\u043a\u0430 \u043f\u043e \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u0443, \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <strong>onChange<\/strong>.<\/p>\n<p>\u0412\u044b\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0431\u0443\u0434\u0435\u0442 \u0441\u043f\u0440\u044f\u0442\u0430\u043d \u0437\u0430 \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0439 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433.<\/p>\n<p>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0437\u0430\u0431\u0435\u0433\u0430\u044f \u0432\u043f\u0435\u0440\u0451\u0434, \u043e\u043f\u0438\u0448\u0435\u043c \u0442\u0430\u043a \u0436\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043d\u0430\u0448\u0435\u0433\u043e Option \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430:<\/p>\n<pre><code class=\"typescript\">type OptionProps = {   option: Option;   onClick: (value: Option['value']) =&gt; void; }; <\/code><\/pre>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 Select:<\/p>\n<pre><code class=\"typescript\">type SelectProps = {   selected: Option | null;   options: Option[];   placeholder?: string;   mode?: 'rows' | 'cells';   status?: 'default' | 'invalid';   onChange?: (selected: Option['value']) =&gt; void;   onClose?: () =&gt; void; };  const Select = (props: SelectProps) =&gt; {   const {     mode = 'rows',     options,     placeholder,     status = 'default',     selected,     onChange,     onClose,   } = props;   const [isOpen, setIsOpen] = useState&lt;boolean&gt;(false);   const rootRef = useRef&lt;HTMLDivElement&gt;(null);    useEffect(() =&gt; {     const handleClick = (event: MouseEvent) =&gt; {       const { target } = event;       if (target instanceof Node &amp;&amp; !rootRef.current?.contains(target)) {         isOpen &amp;&amp; onClose?.();         setIsOpen(false);       }     };      window.addEventListener('click', handleClick);      return () =&gt; {       window.removeEventListener('click', handleClick);     };   }, [isOpen, onClose]);    const handleOptionClick = (value: Option['value']) =&gt; {     setIsOpen(false);     onChange?.(value);   };   const handlePlaceHolderClick: MouseEventHandler&lt;HTMLDivElement&gt; = () =&gt; {     setIsOpen((prev) =&gt; !prev);   };    return (     &lt;div       className={Styles.selectWrapper}       ref={rootRef}       data-is-active={isOpen}       data-mode={mode}     &gt;       &lt;div<\/code><\/pre>\n<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-347474","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/347474","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=347474"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/347474\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=347474"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=347474"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=347474"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}