Skip to content

Commit

Permalink
#68 Allow hidden content objects to be used in navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
swashbuck committed Jun 21, 2024
1 parent de8d35c commit 46cd185
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
20 changes: 9 additions & 11 deletions js/PageNavModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@ class PageNavModel extends ComponentModel {
if (!buttonConfig._isEnabled) continue;

// Get models, skipping any undefined types (ex. deprecated button types)
let buttonModel = buttonTypeModels[type];
if (!buttonModel && !buttonConfig._customRouteId) continue;

// Find buttonModel from config._customRouteId if not found in defined type
if (buttonConfig._customRouteId) {
buttonModel = data.findById(buttonConfig._customRouteId);
if (!buttonModel) continue;
}
const buttonModel = buttonConfig._customRouteId
? data.findById(buttonConfig._customRouteId)
: buttonTypeModels[type];

if (!buttonModel) continue;

// Convert found buttonModel to json if exists or create an 'undefined' json
item = buttonModel ? buttonModel.toJSON() : { _isHidden: true };
Expand Down Expand Up @@ -107,8 +105,8 @@ class PageNavModel extends ComponentModel {
let hasFoundCurrentPage = false;

for (const page of pages.reverse()) {
const isNotAvailable = !page.get('_isAvailable');
if (isNotAvailable) continue;
const isNotShown = !page.get('_isAvailable') || page.get('_isHidden');
if (isNotShown) continue;

if (!hasFoundCurrentPage) {
hasFoundCurrentPage = page.get('_id') === currentPageId;
Expand All @@ -128,8 +126,8 @@ class PageNavModel extends ComponentModel {
let hasFoundCurrentPage = false;

for (const page of pages) {
const isNotAvailable = !page.get('_isAvailable');
if (isNotAvailable) continue;
const isNotShown = !page.get('_isAvailable') || page.get('_isHidden');
if (isNotShown) continue;

if (!hasFoundCurrentPage) {
hasFoundCurrentPage = page.get('_id') === currentPageId;
Expand Down
6 changes: 2 additions & 4 deletions js/PageNavView.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ class PageNavView extends ComponentView {
return;
}

// Check if locked
const isLocked = item._isHidden || item._isLocked;
if (isLocked) return;
if (item._isLocked) return;

this.navigateTo(item._id);
};
Expand All @@ -67,7 +65,7 @@ class PageNavView extends ComponentView {
setupTooltips() {
const items = this.model.get('_items');
items.forEach(item => {
if (!item._tooltip || item._isHidden) return;
if (!item._tooltip) return;

tooltips.register({
_id: item._tooltipId,
Expand Down
6 changes: 2 additions & 4 deletions templates/pageNavItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export default function PageNavItem(props) {
_iconClass,
_id,
_index,
_isHidden,
_tooltipId,
ariaLabel,
locked,
Expand All @@ -27,17 +26,16 @@ export default function PageNavItem(props) {
_iconClass && 'btn-icon has-icon',
_iconAlignment && `has-icon-${_iconAlignment}`,
text && 'btn-text has-text',
_isHidden && 'is-hidden',
locked && 'is-locked',
(_isHidden || locked) && 'is-disabled',
locked && 'is-disabled',
_classes
])}
role="link"
data-type={type}
data-id={_id}
data-item-index={_index}
data-tooltip-id={_tooltipId}
disabled={_isHidden || locked}
disabled={locked}
aria-label={`${locked ? globals._accessibility._ariaLabels.locked + '. ' : ''}${compile(ariaLabel, props)}`}
onClick={onButtonClick}
>
Expand Down

0 comments on commit 46cd185

Please sign in to comment.