Skip to content

Commit ae5db9c

Browse files
committed
Utils.getElements('1') support
* fix #2234 * `Utils.getElements('1')` (called by removeWidget() and others) now checks for digit 'selector' (becomes an id)
1 parent 612f621 commit ae5db9c

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

demo/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ <h1>Demos</h1>
1414
<li><a href="column.html">Column</a></li>
1515
<li><a href="float.html">Float grid</a></li>
1616
<li><a href="knockout.html">Knockout.js</a></li>
17-
<li><a href="mobile.html">Mobile touch (JQ)</a></li>
17+
<li><a href="mobile.html">Mobile touch</a></li>
1818
<li><a href="nested.html">Nested grids</a></li>
1919
<li><a href="nested_constraint.html">Nested Constraint grids</a></li>
2020
<li><a href="nested_advanced.html">Nested Advanced grids</a></li>

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ Change log
8686

8787
## 8.0.0-dev (TBD)
8888
* feat: [#2275](https://github.com/gridstack/gridstack.js/issues/2275) `setupDragIn()` now can take an array or elements (in addition to selector string) and optional parent root (for shadow DOM support)
89+
* fix: [#2234](https://github.com/gridstack/gridstack.js/issues/2234) `Utils.getElements('1')` (called by removeWidget() and others) now checks for digit 'selector' (becomes an id).
8990

9091
## 8.0.0 (2023-04-29)
9192
* package is now ES2020 (TS exported files), webpack all.js still umd (better than commonjs for browsers), still have es5/ files unchanged (for now)

src/utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ export class Utils {
5656
/** convert a potential selector into actual list of html elements. optional root which defaults to document (for shadow dom) */
5757
static getElements(els: GridStackElement, root = document): HTMLElement[] {
5858
if (typeof els === 'string') {
59+
60+
// Note: very common for people use to id='1,2,3' which is only legal as HTML5 id, but not CSS selectors
61+
// so if we start with a number, assume it's an id and just return that one item...
62+
// see https://github.com/gridstack/gridstack.js/issues/2234#issuecomment-1523796562
63+
if(!isNaN(+els[0])) { // start with digit
64+
const el = root.getElementById(els);
65+
return el ? [el] : [];
66+
}
67+
5968
let list = root.querySelectorAll(els);
6069
if (!list.length && els[0] !== '.' && els[0] !== '#') {
6170
list = root.querySelectorAll('.' + els);

0 commit comments

Comments
 (0)