Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: Add option for disabled button text (fixes #207) #214

Merged
merged 9 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@ The attributes listed below are properly formatted as JSON in [*example.json*](h

>>**text** (string): Defines the default button text. The default is `"Continue"`.

>>**disabledText** (string): Defines the default button text when the button is disabled. If not set, `text`, `startText`, or `finalText` will be used. `_styleBeforeCompletion` must be set to `visible`. The default is `""`.
oliverfoster marked this conversation as resolved.
Show resolved Hide resolved

>>**ariaLabel** (string): Defines the default button aria label. The default is `""`.

>>**disabledAriaLabel** (string): Defines the button aria label when using `disabledText`. The default is `""`.

>>**startText** (string): Defines the first item button text when set on the article with **\_onChildren** set to `true`. The default is `"Begin"`.

>>**startAriaLabel** (string): Defines the first item button aria label when set on the article with **\_onChildren** set to `true`. The default is `""`.
Expand Down
2 changes: 2 additions & 0 deletions example.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
"_className": "",
"_hasIcon": false,
"text": "Continue",
"disabledText": "",
"ariaLabel": "",
"disabledAriaLabel": "",
"startText": "Begin",
"startAriaLabel": "",
"finalText": "Finish",
Expand Down
19 changes: 13 additions & 6 deletions js/TrickleButtonModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export default class TrickleButtonModel extends ComponentModel {
if (!trickleConfig) return;
let isStart = false;
let isFinal = false;
const isDisabled = this.get('_isButtonDisabled');
if (trickleConfig._onChildren) {
const parentId = parentModel.get('_id');
const trickleParent = getModelContainer(parentModel);
Expand All @@ -128,16 +129,22 @@ export default class TrickleButtonModel extends ComponentModel {
isStart = (index === 0);
isFinal = (index === trickleSiblings.length - 1 && !trickleParent.get('_canRequestChild'));
}
const text = (isStart && trickleConfig._button.startText) ?
const text = (isDisabled && trickleConfig._button.disabledText) ?
trickleConfig._button.disabledText :
(isStart && trickleConfig._button.startText) ?
trickleConfig._button.startText :
(isFinal && trickleConfig._button.finalText) ?
trickleConfig._button.finalText :
trickleConfig._button.text;
const ariaLabel = (isStart && trickleConfig._button.startAriaLabel) ?
trickleConfig._button.finalText :
trickleConfig._button.text;

const ariaLabel = (isDisabled && trickleConfig._button.disabledAriaLabel) ?
trickleConfig._button.disabledAriaLabel :
(isStart && trickleConfig._button.startAriaLabel) ?
trickleConfig._button.startAriaLabel :
(isFinal && trickleConfig._button.finalAriaLabel) ?
trickleConfig._button.finalAriaLabel :
trickleConfig._button.ariaLabel;
trickleConfig._button.finalAriaLabel :
trickleConfig._button.ariaLabel;

this.set({
buttonText: text,
buttonAriaLabel: ariaLabel
Expand Down
3 changes: 2 additions & 1 deletion js/TrickleButtonView.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class TrickleButtonView extends ComponentView {
this.openPopupCount = 0;
this.isAwaitingPopupClose = false;
this.wasButtonClicked = false;
this.model.calculateButtonText();
this.calculateButtonState();
this.model.calculateButtonText();
this.setupEventListeners();
this.render();
if (!this.model.isEnabled()) {
Expand Down Expand Up @@ -131,6 +131,7 @@ class TrickleButtonView extends ComponentView {
const isButtonLocked = (this.model.get('_isButtonVisible')) && isButtonDisabled;
$button.toggleClass('is-locked', isButtonLocked);
const $buttonText = this.$('.js-trickle-btn-text');
this.model.calculateButtonText();
const text = this.model.get('buttonText');
const ariaLabel = this.model.get('buttonAriaLabel');
$buttonText.html(text);
Expand Down
40 changes: 40 additions & 0 deletions properties.schema
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,16 @@
"validators": [],
"translatable": true
},
"disabledText": {
"type": "string",
"required": false,
"default": "",
"title": "Button Text when disabled",
"inputType": "Text",
"validators": [],
"translatable": true,
"help": "This text can be shown while the button is disabled"
},
"ariaLabel": {
"type": "string",
"required": false,
Expand All @@ -215,6 +225,16 @@
"validators": [],
"translatable": true
},
"disabledAriaLabel": {
"type": "string",
"required": false,
"default": "",
"title": "Button Aria Label when disabled",
"inputType": "Text",
"validators": [],
"translatable": true,
"help": "The aria label when 'Button Text when disabled' is set"
},
"startText": {
"type": "string",
"required": false,
Expand Down Expand Up @@ -441,6 +461,16 @@
"validators": [],
"translatable": true
},
"disabledText": {
"type": "string",
"required": false,
"default": "",
"title": "Button Text when disabled",
"inputType": "Text",
"validators": [],
"translatable": true,
"help": "This text can be shown while the button is disabled"
},
"ariaLabel": {
"type": "string",
"required": false,
Expand All @@ -450,6 +480,16 @@
"validators": [],
"translatable": true
},
"disabledAriaLabel": {
"type": "string",
"required": false,
"default": "Continue",
"title": "Button Aria Label when disabled",
"inputType": "Text",
"validators": [],
"translatable": true,
"help": "The aria label when 'Button Text when disabled' is set"
},
"startText": {
"type": "string",
"required": false,
Expand Down
18 changes: 18 additions & 0 deletions schema/article.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@
"translatable": true
}
},
"disabledText": {
cahirodoherty-learningpool marked this conversation as resolved.
Show resolved Hide resolved
"type": "string",
"title": "Button text when disabled",
"default": "",
"description": "This text can be shown while the button is disabled",
"_adapt": {
"translatable": true
}
},
"ariaLabel": {
"type": "string",
"title": "Default button ARIA label",
Expand All @@ -134,6 +143,15 @@
"translatable": true
}
},
"disabledAriaLabel": {
"type": "string",
"title": "Button ARIA label when disabled",
"default": "",
"description": "The aria label when 'Button text when disabled' is set",
"_adapt": {
"translatable": true
}
},
"startText": {
"type": "string",
"title": "First button text",
Expand Down
18 changes: 18 additions & 0 deletions schema/block.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@
"translatable": true
}
},
"disabledText": {
"type": "string",
"title": "Button text when disabled",
"default": "",
"description": "This text can be shown while the button is disabled",
"_adapt": {
"translatable": true
}
},
"ariaLabel": {
"type": "string",
"title": "Default button ARIA label",
Expand All @@ -129,6 +138,15 @@
"translatable": true
}
},
"disabledAriaLabel": {
"type": "string",
"title": "Button ARIA label when disabled",
"default": "",
"description": "The aria label when 'Button text when disabled' is set",
"_adapt": {
"translatable": true
}
},
"startText": {
"type": "string",
"title": "First button text",
Expand Down