Giter Club home page Giter Club logo

atom-select-list's Introduction

Atom and all repositories under Atom will be archived on December 15, 2022. Learn more in our official announcement

atom-select-list

This module is an etch component that can be used in Atom packages to show a select list with fuzzy filtering, keyboard/mouse navigation and other cool features.

Installation

npm install --save atom-select-list

Usage

After installing the module, you can simply require it and use it as a standalone component:

const SelectList = require('atom-select-list')

const usersSelectList = new SelectList({
  items: ['Alice', 'Bob', 'Carol']
})
document.body.appendChild(usersSelectList.element)

Or within another etch component:

render () {
  return (
    <SelectList items={this.items} />
  )
}

API

When creating a new instance of a select list, or when calling update on an existing one, you can supply a JavaScript object that can contain any of the following properties:

  • items: [Object]: an array containing the objects you want to show in the select list.
  • elementForItem: (item: Object, options: Object) -> HTMLElement: a function that is called whenever an item needs to be displayed.
    • options: Object:
      • selected: Boolean: indicating whether item is selected or not.
      • index: Number: item's index.
      • visible: Boolean: indicating whether item is visible in viewport or not. Unless initiallyVisibleItemCount was given, this value is always true.
  • (Optional) maxResults: Number: the number of maximum items that are shown.
  • (Optional) filter: (items: [Object], query: String) -> [Object]: a function that allows to decide which items to show whenever the query changes. By default, it uses fuzzaldrin to filter results.
  • (Optional) filterKeyForItem: (item: Object) -> String: when filter is not provided, this function will be called to retrieve a string property on each item and that will be used to filter them.
  • (Optional) filterQuery: (query: String) -> String: a function that allows to apply a transformation to the user query and whose return value will be used to filter items.
  • (Optional) query: String: a string that will replace the contents of the query editor.
  • (Optional) selectQuery: Boolean: a boolean indicating whether the query text should be selected or not.
  • (Optional) order: (item1: Object, item2: Object) -> Number: a function that allows to change the order in which items are shown.
  • (Optional) emptyMessage: String: a string shown when the list is empty.
  • (Optional) errorMessage: String: a string that needs to be set when you want to notify the user that an error occurred.
  • (Optional) infoMessage: String: a string that needs to be set when you want to provide some information to the user.
  • (Optional) loadingMessage: String: a string that needs to be set when you are loading items in the background.
  • (Optional) loadingBadge: String/Number: a string or number that needs to be set when the progress status changes (e.g. a percentage showing how many items have been loaded so far).
  • (Optional) itemsClassList: [String]: an array of strings that will be added as class names to the items element.
  • (Optional) initialSelectionIndex: Number: the index of the item to initially select and automatically select after query changes; defaults to 0.
  • (Optional) didChangeQuery: (query: String) -> Void: a function that is called when the query changes.
  • (Optional) didChangeSelection: (item: Object) -> Void: a function that is called when the selected item changes.
  • (Optional) didConfirmSelection: (item: Object) -> Void: a function that is called when the user clicks or presses Enter on an item.
  • (Optional) didConfirmEmptySelection: () -> Void: a function that is called when the user presses Enter but the list is empty.
  • (Optional) didCancelSelection: () -> Void: a function that is called when the user presses Esc or the list loses focus.
  • (Optional) initiallyVisibleItemCount: Number: When this options was provided, SelectList observe visibility of items in viewport, visibility state is passed as visible option to elementForItem. This is mainly used to skip heavy computation for invisible items.

atom-select-list's People

Contributors

50wliu avatar aminya avatar ben3eee avatar darangi avatar daviwil avatar eeejay avatar iolsen avatar jarle avatar josa42 avatar kant avatar leroix avatar lexicalunit avatar mateusvahl avatar maxbrunsfeld avatar nshikov avatar sadick254 avatar t9md avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

atom-select-list's Issues

Opening a second Select List reverts focus to editor

Prerequisites

Description

Opening a second Select List on top of another results in the Select List being unfocused, and reverts focus to the editor.

Steps to Reproduce

  1. Open Fuzzy Finder
  2. Open Command Palette without closing the Fuzzy Finder

Expected behavior:
Command Palette is focused - typing results in text in field.

Actual behavior:
Command Palette is not focused - typing does not result in text in field.
Typing results in text on currently opened file.

Reproduces how often:
100% reproduce rate from a small number of tests.

Versions

macOS 10.11.5

Atom : 1.16.0-beta0
Electron: 1.3.13
Chrome : 52.0.2743.82
Node : 6.5.0

apm 1.16.1
npm 3.10.5
node 6.9.5 x64
python 2.7.10
git 2.10.1

Expose a setQuery method in SelectListView

Hi guys,

I feel it would be useful to provide a setQuery method to set the text in the internal TextEditor. Currently this can be done using

selectListView.refs.queryEditor.setText

This is not a good way to do it as it makes assumptions on the internals of the class.

Need
This would provide more flexibility in how the functionality of select view can be used.

Let me know what you guys think.

Thanks,
Sanketh

Add a README and CHANGELOG

I had to dig through command-palette package to see this package's API to use it in linter. Having a README with an API and a basic example would be nice

Having a CHANGELOG would help a lot with version upgrades (we won't have to read commit history anymore)

select list toggle time is long for very big lists

In my case, the fuzzy finder loads a project with 200k files.
When I press ctrl+p, it takes several seconds for the select list to appear, and if I blur the list, it takes several more seconds for it to disappear. In the meanwhile, the UI hangs.

I narrowed this down to computeItems. It takes almost 3 seconds to splice a very large array into the allowed maxResults size.

Add support for as-you-type autocomplete

As it's currently implemented, there's no evident event hook that could be used to support an autocomplete feature. Initially I tried to use didChangeQuery(). I got the TextEditor model out of the SelectList via selectList.refs.queryEditor, then I intended to do something like:

item = whatever() // the item we want to autocomplete to
editor.setText(item.title)
editor.selectLeft(item.title.length - query.length)

But of course using editor.setText() here triggers didChangeQuery() and causes an infinite loop. More than that though, it also triggers a filter process for the autocompleted item's text :(

I tried to work around it by using some state to make the next didChangeQuery() and filter() calls into no-ops after doing an autocompletion but it was really janky and slow and I just couldn't get it to work right. This seems like it would be better implemented within atom-select-list somehow.

Rollup Warning: This expression is not constructable

Prerequisites

None of the prerequisites applies to this bug

Description

Since upgrading to v0.8.0, Rollup reports the following warning when trying to compile a script that instantiates the SelectList class:

(!) Plugin typescript: @rollup/plugin-typescript TS2351: This expression is not constructable.
Type 'typeof import(".../node_modules/atom-select-list/lib/select-list-view")' has no construct signatures.

Steps to Reproduce

  1. Add [email protected] as a package dependency
  2. Instantiate the class new SelectList() in a package written in TypeScript
  3. Build using Rollup

Versions

Atom    : 1.54.0
Electron: 6.1.12
Chrome  : 76.0.3809.146
Node    : 12.4.0

$ apm --version
apm  2.5.2
npm  6.14.8
node 12.4.0 x64
atom 1.54.0
python 2.7.16
git 2.30.1

Support configurable auto-selection

I'd like to use this component, but I need to be able to configure it to select nothing by default. When filtering it should still filter items just the same, but just don't automatically select the first item in the list after each filtering process has completed. Pressing enter when there are items in the list, but none are selected, should result in didConfirmEmptySelection() being called.

My existing use case for this is a list of existing documents. While typing out a query, it filters the document list to show relevant matches. However, as long as no document is yet selected, confirmation will create a new document with name set to the current query filter. It's this last part that can't be done with atom-select-list as it's currently written.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.