Skip to content

Commit

Permalink
KYAN-293 add authorable id attribute to Button (#507)
Browse files Browse the repository at this point in the history
* KYAN-293 add authorable id attribute to Button

* KYAN-293 update e2e-tests for Button

* KYAN-293 add changes due to PR review
  • Loading branch information
KorzunYuri authored Oct 1, 2024
1 parent 4096b77 commit 7e0fae2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public class ButtonComponent {
@Getter
private boolean hideLabel;

@ValueMapValue
@Getter
private String buttonId;

@Inject
@Getter
private boolean showIconLeft;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,26 @@
*/-->
<sly data-sly-use.model="pl.ds.kyanite.common.components.models.ButtonComponent">
<sly data-sly-test="${model.type == 'button'}">
<sly data-sly-test.disabled="${model.isDisabled}">
<button class="button ${model.buttonClasses @ join=' '}" disabled
aria-label="${model.hideLabel ? model.label : ''}">
<sly data-sly-use.template="./template.html"
data-sly-call="${template.buttonContent @ model = model}"></sly>
</button>
</sly>
<sly data-sly-test="${!disabled}">
<sly data-sly-test="${model.actionType == 'open-modal'}">
<button class="button js-modal-trigger ${model.buttonClasses @ join=' '}"
data-target="${model.modalId}"
aria-label="${model.hideLabel ? model.label : ''}">
<sly data-sly-use.template="./template.html"
data-sly-call="${template.buttonContent @ model = model}"></sly>
</button>
</sly>

<sly data-sly-test="${model.actionType != 'open-modal'}">
<button class="button ${model.buttonClasses @ join=' '}"
aria-label="${model.hideLabel ? model.label : ''}">
<sly data-sly-use.template="./template.html"
data-sly-call="${template.buttonContent @ model = model}"></sly>
</button>
</sly>
</sly>
<sly data-sly-set.isDisabled="${model.isDisabled}"
data-sly-set.isModal="${!isDisabled && (model.actionType == 'open-modal')}"></sly>
<button class="button ${model.buttonClasses @ join=' '}
${isModal ? 'js-modal-trigger' : ''}"
id="${model.buttonId}"
data-sly-attribute.data-target="${isModal ? model.modalId : ''}"
data-sly-attribute.disabled="${isDisabled}"
aria-label="${model.hideLabel ? model.label : ''}">
<sly data-sly-use.template="./template.html"
data-sly-call="${template.buttonContent @ model = model}"></sly>
</button>
</sly>
<sly data-sly-test="${model.type == 'a'}">
<a href="${model.url}" data-part1="${model.mailPart1}" data-part2="${model.mailPart2}" data-part3="${model.mailPart3}" class="button ${model.buttonClasses @ join=' '}"
<a href="${model.url}" data-part1="${model.mailPart1}" data-part2="${model.mailPart2}" data-part3="${model.mailPart3}"
class="button ${model.buttonClasses @ join=' '}"
id="${model.buttonId}"
target="${model.openInNewTab && model.url != '' ? '_blank' : ''}"
aria-label="${model.hideLabel ? model.label : ''}">
<sly data-sly-use.template="./template.html"
data-sly-call="${template.buttonContent @ model = model}"></sly>
</a>
</sly>
</sly>
</sly>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
"label": "Hide label",
"description": "Use to describe link without showing the label. Can be useful e.g. to describe link with an icon"
},
"buttonId": {
"sling:resourceType": "wcm/dialogs/components/textfield",
"name": "buttonId",
"label": "Button ID",
"description": "ID used for Google Analytics purposes"
},
"type": {
"sling:resourceType": "wcm/dialogs/components/include",
"path": "/libs/kyanite/common/components/button/attributes/type"
Expand Down Expand Up @@ -456,4 +462,4 @@
}
}
}
}
}
6 changes: 4 additions & 2 deletions tests/end-to-end/tests/elements/button.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ describe('Button component', function () {
'iconLibType': 'mdi',
'icon': 'mdi-cube-outline',
'selectOrType': 'select'
}
},
'buttonId': ''
});
});

Expand Down Expand Up @@ -195,7 +196,8 @@ describe('Button component', function () {
'label': 'Label',
'sling:resourceType': 'kyanite/common/components/button',
'openInNewTab': 'true',
'isMailto': 'false'
'isMailto': 'false',
'buttonId': ''
});
});
});

0 comments on commit 7e0fae2

Please sign in to comment.