Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
focus-group
Advanced tools
Create a group of nodes with special focus-related powers.
Specifically, you can do the following with your focus group:
Essentially, it mimics some of the essential keyboard interactions of a native <select>
.
These kinds of powers are useful for:
A focus-group is composed of members.
The order of the members matters, because focus moves forwards and backwards through the group, in order.
Each member consists of a DOM node and some text associated with that node. The member's text will be used for letter-key jumping (a.k.a. string searching). Each member's text can be established in a few ways:
setMembers()
or addMember()
(see below).data-focus-group-text
attribute, that value will serve as the member's text.textContent
of its node.When focus is inside the focus-group, the following things should happen:
forwardArrows
(the down arrow by default), focus moves
from the currently focused member to the next member in the group (or wraps back
to the front, according to the wrap
option).backArrows
(the up arrow by default), focus moves
from the currently focused member to the previous member in the group (or wraps around
to the back, according to the wrap
option).If the option stringSearch
is true
and focus is within the group, the following things happen:
stringSearchDelay
,
the search string will extend (e.g. f
-> fa
-> far
-> farm
) and focus will move
accordingly.stringSearchDelay
, the search
string resets and you can start over (e.g. you type fa
then wait and type go
to match gorge
).This all mimics the native <select>
behavior.
Note that like the native <select>
, typing only matches the beginning of words. So you can't focus David Clark
by typing Clark
.
This is the function you get when you require()
or import
the module.
var createFocusGroup = require('focus-group');
var myMegaMenuFocusGroup = createFocusGroup();
members { Array }: Designate initial members of the group. Can be any of the following:
querySelectorAll()
)node
(the DOM node),
and (optionally) text
(the text that should be associated with that node for letter-navigation)You can omit this option and add members later with addMember()
or setMembers()
. Default: []
.
forwardArrows { Array of 'up'
, 'down'
, 'left'
, or 'right'
}:
Specify which arrows should move the focus forward through the group (e.g. from index 2 to index 3).
Default: [ 'down' ]
backArrows { Array of 'up'
, 'down'
, 'left'
, or 'right'
}:
Specify which arrows should move the focus back through the group (e.g. from index 4 to index 3).
Default: [ 'up' ]
wrap { Boolean }:
If true
, when the arrow keys are moving focus they will wrap around the group. That is, when focus is on the last item and you move focus forward, the first item will focus; and when focus is on the first item and you move focus back, the last item will focus.
stringSearch { Boolean }:
If true
, string searching is enabled (see below).
Default: false
.
stringSearchDelay { Number }:
The number of milliseconds that should elapse between the user's last letter entry (with the keyboard)
and a refresh of the string search (see below).
Default: 800
.
Start this group listening to keyboard events and responding accordingly.
Returns the focus group instance.
Stop this group listening to keyboard events.
Returns the focus group instance.
Add a member to the group.
member
can be any of the following:
node
(the node itself)text
: Text that should be associated with that node for letter-navigation. If none is provided, focus-group will check for a data-focus-group-text
attribute or fallback to the node's textContent.
If index
is provided, the member will be added at that index.
Otherwise, it will be added to the end of the group.
Returns the focus group instance.
Remove a member from the group.
member
can be any of the following:
Returns the focus group instance.
Empty the focus group of members.
Returns the focus group instance.
Set the focus group's members (clearing any that already exist).
members
can be any of the following:
querySelectorAll()
)node
(the node itself)text
: Text that should be associated with that node for letter-navigation. If none is provided, focus-group will check for a data-focus-group-text
attribute or fallback to the node's `textContent.Returns the focus group instance.
Returns the focus group's current array of members.
Each item in the array is an object with node
and text
properties.
Focuses the node at a particular index in the focus group's member array.
If no member exists at that index, does nothing.
Returns the focus group instance.
Moves the focus forward one member, if focus is already within the group.
If focus is not within the group, does nothing.
Returns the index of the newly focused member.
Moves the focus back one member, if focus is already within the group.
If focus is not within the group, does nothing.
Returns the index of the newly focused member.
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
FAQs
Create a group of nodes with special focusing powers
The npm package focus-group receives a total of 23,766 weekly downloads. As such, focus-group popularity was classified as popular.
We found that focus-group demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.