✨feature: Add field for ARIA label in button block
This commit is contained in:
@@ -26,7 +26,8 @@
|
|||||||
"other_choice": 0,
|
"other_choice": 0,
|
||||||
"allow_in_bindings": 0,
|
"allow_in_bindings": 0,
|
||||||
"layout": "horizontal",
|
"layout": "horizontal",
|
||||||
"save_other_choice": 0
|
"save_other_choice": 0,
|
||||||
|
"wpml_cf_preferences": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "field_5f7f85a71151d",
|
"key": "field_5f7f85a71151d",
|
||||||
@@ -42,7 +43,8 @@
|
|||||||
"class": "",
|
"class": "",
|
||||||
"id": ""
|
"id": ""
|
||||||
},
|
},
|
||||||
"return_format": "array"
|
"return_format": "array",
|
||||||
|
"wpml_cf_preferences": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "field_5f7f85bd1151e",
|
"key": "field_5f7f85bd1151e",
|
||||||
@@ -71,7 +73,10 @@
|
|||||||
"allow_in_bindings": 1,
|
"allow_in_bindings": 1,
|
||||||
"ui": 0,
|
"ui": 0,
|
||||||
"ajax": 0,
|
"ajax": 0,
|
||||||
"placeholder": ""
|
"placeholder": "",
|
||||||
|
"create_options": 0,
|
||||||
|
"save_options": 0,
|
||||||
|
"wpml_cf_preferences": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "field_5f7f85e41151f",
|
"key": "field_5f7f85e41151f",
|
||||||
@@ -97,7 +102,10 @@
|
|||||||
"ui": 0,
|
"ui": 0,
|
||||||
"return_format": "value",
|
"return_format": "value",
|
||||||
"ajax": 0,
|
"ajax": 0,
|
||||||
"placeholder": ""
|
"placeholder": "",
|
||||||
|
"create_options": 0,
|
||||||
|
"save_options": 0,
|
||||||
|
"wpml_cf_preferences": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "field_5f807a47dd2a8",
|
"key": "field_5f807a47dd2a8",
|
||||||
@@ -125,7 +133,10 @@
|
|||||||
"allow_in_bindings": 1,
|
"allow_in_bindings": 1,
|
||||||
"ui": 0,
|
"ui": 0,
|
||||||
"ajax": 0,
|
"ajax": 0,
|
||||||
"placeholder": ""
|
"placeholder": "",
|
||||||
|
"create_options": 0,
|
||||||
|
"save_options": 0,
|
||||||
|
"wpml_cf_preferences": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "field_605924972a98a",
|
"key": "field_605924972a98a",
|
||||||
@@ -154,7 +165,32 @@
|
|||||||
"allow_in_bindings": 1,
|
"allow_in_bindings": 1,
|
||||||
"ui": 0,
|
"ui": 0,
|
||||||
"ajax": 0,
|
"ajax": 0,
|
||||||
"placeholder": ""
|
"placeholder": "",
|
||||||
|
"create_options": 0,
|
||||||
|
"save_options": 0,
|
||||||
|
"wpml_cf_preferences": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "field_6924c83e85da9",
|
||||||
|
"label": "ARIA Label",
|
||||||
|
"name": "aria_label",
|
||||||
|
"aria-label": "",
|
||||||
|
"type": "text",
|
||||||
|
"instructions": "Used to give the link an accessible name if using \"Read more\" as the title",
|
||||||
|
"required": 0,
|
||||||
|
"conditional_logic": 0,
|
||||||
|
"wrapper": {
|
||||||
|
"width": "",
|
||||||
|
"class": "",
|
||||||
|
"id": ""
|
||||||
|
},
|
||||||
|
"wpml_cf_preferences": 0,
|
||||||
|
"default_value": "",
|
||||||
|
"maxlength": "",
|
||||||
|
"allow_in_bindings": 0,
|
||||||
|
"placeholder": "",
|
||||||
|
"prepend": "",
|
||||||
|
"append": ""
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"location": [
|
"location": [
|
||||||
@@ -175,5 +211,7 @@
|
|||||||
"active": true,
|
"active": true,
|
||||||
"description": "",
|
"description": "",
|
||||||
"show_in_rest": 0,
|
"show_in_rest": 0,
|
||||||
"modified": 1742236256
|
"display_title": "",
|
||||||
|
"acfml_field_group_mode": "translation",
|
||||||
|
"modified": 1764018311
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ class ButtonComponent extends HTMLElement {
|
|||||||
* - url: The URL to link to.
|
* - url: The URL to link to.
|
||||||
* - target: The target for the link.
|
* - target: The target for the link.
|
||||||
* - title: The text to display on the button.
|
* - title: The text to display on the button.
|
||||||
|
* - ariaLabel: The ARIA label for the button.
|
||||||
* - color: The color of the button.
|
* - color: The color of the button.
|
||||||
* - variant: The variant of the button.
|
* - variant: The variant of the button.
|
||||||
* - size: The size of the button.
|
* - size: The size of the button.
|
||||||
@@ -30,6 +31,7 @@ class ButtonComponent extends HTMLElement {
|
|||||||
'url',
|
'url',
|
||||||
'target',
|
'target',
|
||||||
'title',
|
'title',
|
||||||
|
'ariaLabel',
|
||||||
'color',
|
'color',
|
||||||
'variant',
|
'variant',
|
||||||
'size',
|
'size',
|
||||||
@@ -44,6 +46,20 @@ class ButtonComponent extends HTMLElement {
|
|||||||
update() {
|
update() {
|
||||||
const btn = this.querySelector(this.getAttribute('element'));
|
const btn = this.querySelector(this.getAttribute('element'));
|
||||||
|
|
||||||
|
// console.log('[ButtonComponent] attributes', {
|
||||||
|
// btnClasses: this.getAttribute('btnClasses'),
|
||||||
|
// element: this.getAttribute('element'),
|
||||||
|
// type: this.getAttribute('type'),
|
||||||
|
// url: this.getAttribute('url'),
|
||||||
|
// target: this.getAttribute('target'),
|
||||||
|
// title: this.getAttribute('title'),
|
||||||
|
// ariaLabel: this.getAttribute('ariaLabel'),
|
||||||
|
// color: this.getAttribute('color'),
|
||||||
|
// variant: this.getAttribute('variant'),
|
||||||
|
// size: this.getAttribute('size'),
|
||||||
|
// width: this.getAttribute('width'),
|
||||||
|
// });
|
||||||
|
|
||||||
if (btn) {
|
if (btn) {
|
||||||
btn.classList = this.getAttribute('btnClasses') || '';
|
btn.classList = this.getAttribute('btnClasses') || '';
|
||||||
|
|
||||||
@@ -63,6 +79,13 @@ class ButtonComponent extends HTMLElement {
|
|||||||
btn.title = this.getAttribute('title') || '';
|
btn.title = this.getAttribute('title') || '';
|
||||||
btn.textContent = this.getAttribute('title') || '';
|
btn.textContent = this.getAttribute('title') || '';
|
||||||
|
|
||||||
|
if (!this.getAttribute('ariaLabel') && this.getAttribute('url')) {
|
||||||
|
btn.setAttribute('aria-label', `Link to ${this.getAttribute('url')}`);
|
||||||
|
} else {
|
||||||
|
btn.setAttribute('aria-label', this.getAttribute('ariaLabel'));
|
||||||
|
}
|
||||||
|
|
||||||
|
btn.setAttribute('aria-label', this.getAttribute('ariaLabel'));
|
||||||
btn.setAttribute('data-button-color', this.getAttribute('color'));
|
btn.setAttribute('data-button-color', this.getAttribute('color'));
|
||||||
btn.setAttribute('data-button-variant', this.getAttribute('variant'));
|
btn.setAttribute('data-button-variant', this.getAttribute('variant'));
|
||||||
btn.setAttribute('data-button-size', this.getAttribute('size'));
|
btn.setAttribute('data-button-size', this.getAttribute('size'));
|
||||||
|
|||||||
@@ -10,9 +10,10 @@ namespace BasicWP;
|
|||||||
// Retrieve ACF fields
|
// Retrieve ACF fields
|
||||||
$element = get_field( 'element' ) ? get_field( 'element' ) : 'a';
|
$element = get_field( 'element' ) ? get_field( 'element' ) : 'a';
|
||||||
$btnLink = get_field( 'link' );
|
$btnLink = get_field( 'link' );
|
||||||
$url = $btnLink['url'] ? $btnLink['url'] : '';
|
$url = isset( $btnLink['url'] ) ? $btnLink['url'] : '';
|
||||||
$target = $btnLink['target'] ? $btnLink['target'] : '';
|
$target = isset( $btnLink['target'] ) ? $btnLink['target'] : '';
|
||||||
$btnTitle = $btnLink['title'] ? $btnLink['title'] : 'Button';
|
$btnTitle = isset( $btnLink['title'] ) ? $btnLink['title'] : 'Button';
|
||||||
|
$btnAria = get_field( 'aria_label' ) ? get_field( 'aria_label' ) : '';
|
||||||
$color = get_field( 'color' );
|
$color = get_field( 'color' );
|
||||||
$variant = get_field( 'variant' );
|
$variant = get_field( 'variant' );
|
||||||
$size = get_field( 'size' );
|
$size = get_field( 'size' );
|
||||||
@@ -44,6 +45,7 @@ if ( ! $is_preview ) {
|
|||||||
url="<?php echo esc_url( $url ); ?>"
|
url="<?php echo esc_url( $url ); ?>"
|
||||||
target="<?php echo esc_attr( $target ); ?>"
|
target="<?php echo esc_attr( $target ); ?>"
|
||||||
title="<?php echo esc_attr( $btnTitle ); ?>"
|
title="<?php echo esc_attr( $btnTitle ); ?>"
|
||||||
|
ariaLabel="<?php echo esc_attr( $btnAria ); ?>"
|
||||||
color="<?php echo esc_attr( $color ); ?>"
|
color="<?php echo esc_attr( $color ); ?>"
|
||||||
variant="<?php echo esc_attr( $variant ); ?>"
|
variant="<?php echo esc_attr( $variant ); ?>"
|
||||||
size="<?php echo esc_attr( $size ); ?>"
|
size="<?php echo esc_attr( $size ); ?>"
|
||||||
|
|||||||
Reference in New Issue
Block a user