Skip to content

Commit

Permalink
Should verify whether the default element is within the section
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-chang committed Feb 28, 2022
1 parent d4536c3 commit 1a59d0b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ When it is `true`, elements defined in this section are unnavigable. This proper
+ Type: [Selector](#selector-1) (without @ syntax)
+ Default: `''`

When a section is specified to be the next focused target, e.g. [`focus('some-section-id')`](#spatialnavigationfocussectionidselector-silent) is called, the first element matching `defaultElement` within this section will be chosen first.
When a section is specified to be the next focused target, e.g. [`focus('some-section-id')`](#spatialnavigationfocussectionidselector-silent) is called, the first navigable element matching `defaultElement` within this section will be chosen first.

#### `enterTo`

Expand Down
18 changes: 6 additions & 12 deletions spatial_navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,19 +554,13 @@
}

function getSectionDefaultElement(sectionId) {
var defaultElement = _sections[sectionId].defaultElement;
var defaultElement = parseSelector(_sections[sectionId].defaultElement).find(function(elem) {
return isNavigable(elem, sectionId, true);
});
if (!defaultElement) {
return null;
}
if (typeof defaultElement === 'string') {
defaultElement = parseSelector(defaultElement)[0];
} else if ($ && defaultElement instanceof $) {
defaultElement = defaultElement.get(0);
}
if (isNavigable(defaultElement, sectionId, true)) {
return defaultElement;
}
return null;
return defaultElement;
}

function getSectionLastFocusedElement(sectionId) {
Expand Down Expand Up @@ -898,7 +892,7 @@

function onKeyUp(evt) {
if (evt.altKey || evt.ctrlKey || evt.metaKey || evt.shiftKey) {
return
return;
}
if (!_pause && _sectionCount && evt.keyCode == 13) {
var currentFocusedElement = getCurrentFocusedElement();
Expand Down Expand Up @@ -1212,7 +1206,7 @@
};

window.SpatialNavigation = SpatialNavigation;

/**********************/
/* CommonJS Interface */
/**********************/
Expand Down

0 comments on commit 1a59d0b

Please sign in to comment.