{"id":46267107,"url":"https://github.com/tjmoses/selection-drag","last_synced_at":"2026-03-04T02:23:03.963Z","repository":{"id":65493807,"uuid":"402245802","full_name":"tjmoses/selection-drag","owner":"tjmoses","description":"Allows you to click and create a selection area using JS only.","archived":false,"fork":false,"pushed_at":"2021-11-13T14:08:09.000Z","size":141,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-24T20:41:57.904Z","etag":null,"topics":["click-area-library","drag-selection-library","js-selection","mouse-selection","react-selection-library","select-area","selecto"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/selection-drag","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tjmoses.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-02T00:56:11.000Z","updated_at":"2025-06-12T08:03:48.000Z","dependencies_parsed_at":"2023-01-26T03:01:19.574Z","dependency_job_id":null,"html_url":"https://github.com/tjmoses/selection-drag","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tjmoses/selection-drag","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tjmoses%2Fselection-drag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tjmoses%2Fselection-drag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tjmoses%2Fselection-drag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tjmoses%2Fselection-drag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tjmoses","download_url":"https://codeload.github.com/tjmoses/selection-drag/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tjmoses%2Fselection-drag/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30069875,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T01:03:42.280Z","status":"online","status_checked_at":"2026-03-04T02:00:07.464Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["click-area-library","drag-selection-library","js-selection","mouse-selection","react-selection-library","select-area","selecto"],"created_at":"2026-03-04T02:23:03.497Z","updated_at":"2026-03-04T02:23:03.946Z","avatar_url":"https://github.com/tjmoses.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Selection Drag - JS/TS Mouse Drag Area Selection Library\n\n![npm](https://img.shields.io/npm/v/selection-drag)\n![npm bundle size](https://img.shields.io/bundlephobia/min/selection-drag)\n![GitHub](https://img.shields.io/github/license/tjmoses/selection-drag)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)\n\n\u003e This is a very ✌ lightweight \u0026 `simple` library for selecting an area on mouse click and drag.\n\n## Install\n\n```bash\nnpm install selection-drag\n```\n\n## Features\n\n- Takes in a Container Element and sets up `_selectstart`, `_selectend`, `_selected`, and `_removed` events on it. `_selectend` gets the final list of selected elements, and `_selected` gets each selected one, whereas `_removed` gets each removed one.\n- Also takes in target css selectors for the elements you want selected. The selection container has an id of `selectionRectangle` if you need to use it to add a click off event.\n- Dynamically adds/removes the selection div and has a `cleanUp` method to restart selection, in addition to `disable`/`enable` methods to remove/add the above event listeners.\n- Right and center mouse clicks are ignored, and scrolling is taken into consideration.\n\n## Usage\n\n### Example using JS alone\n\n- [Demo](https://codepen.io/tmoses/pen/VwWaRKL)\n\n```js\n  import selectionDrag from 'selection-drag';\n  ...\n\n  const contentRef = document.querySelector('.container');\n  const sel = selectionDrag({ container: contentRef, targetSelectors: '.listitem'});\n\n  sel.rect.addEventListener('_selectstart', e =\u003e console.log('started!'))\n  sel.rect.addEventListener('_selectend', e =\u003e {\n    const { selectedElements } = e?.detail || {};\n    console.log(selectedElements); // use all *active selected elements\n  });\n  sel.rect.addEventListener('_selected', e =\u003e {\n     e.detail.addedElement.classList.add('active'); // add a class to that element\n  });\n   sel.rect.addEventListener('_removed', e =\u003e {                                       \n     e.detail.removedElement.classList.remove('active'); // remove the added class\n  });\n\n  // other code such as container drop event listeners\n  // remove \u0026 disable mouse selection area\n  // sel.cleanUp();\n  // sel.disable();\n```\n\n### Example using React Hooks \u0026 TS\n\n```TS\n// you can import any name since it uses default exports.\nimport Selection from 'selection-drag';\n...\n  const selectionRef = useRef\u003cReturnType\u003ctypeof Selection\u003e\u003e();\n...\n  useEffect(() =\u003e {\n    if (!selectionRef.current) {\n      const currentContentContainer = document.querySelector('.container');\n      const sel = Selection({\n        container: currentContentContainer,\n        targetSelectors: `.${dynamicClass}`\n      });\n      selectionRef.current = sel;\n      sel.rect.addEventListener('_selectstart', e =\u003e {\n      // do stuff on select start.\n      })\n      sel.rect.addEventListener('_selectend', e =\u003e {\n        const { selectedElements }: \n          { selectedElements: Element[] | undefined } = e?.detail || {};\n        // use all *active selected elements\n      });\n      sel.rect.addEventListener('_selected', e =\u003e\n        // maybe add a hover class for each item selected\n        e?.detail?.addedElement?.classList.add('active')\n      );\n      sel.rect.addEventListener('_removed', e =\u003e\n        // remove the hover class for each item selected\n        e?.detail?.removedElement?.classList.remove('active')\n      );\n    }\n  }, [YourDependencies]);\n  ...\n  // other code event listeners\n  if (selectionRef.current) {\n    // remove \u0026 disable mouse selection area\n    selectionRef.current.cleanUp();\n    selectionRef.current.disable();\n  }\n```\n\nTo support, Please \u0026#127775; if you used / like this library!\n\n## Contributing\n\nPlease see the contributing guidelines [here](contributing.md) for further information. All contributions are appreciated, even if they are just comments from issues.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftjmoses%2Fselection-drag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftjmoses%2Fselection-drag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftjmoses%2Fselection-drag/lists"}