Fix initial panel state handling to prevent yoyo effect on first load
This commit is contained in:
@ -748,24 +748,24 @@ function wp_allstars_settings_page() {
|
|||||||
var $panel = $button.closest('.wp-allstars-toggle').find('.wp-allstars-toggle-settings');
|
var $panel = $button.closest('.wp-allstars-toggle').find('.wp-allstars-toggle-settings');
|
||||||
var $icon = $button.find('.dashicons');
|
var $icon = $button.find('.dashicons');
|
||||||
|
|
||||||
// Set initial state
|
// Set initial state without animation
|
||||||
var isExpanded = $panel.is(':visible');
|
var isExpanded = $button.attr('aria-expanded') === 'true';
|
||||||
$button.attr('aria-expanded', isExpanded);
|
$panel.toggle(isExpanded);
|
||||||
$icon.css('transform', isExpanded ? 'rotate(180deg)' : '');
|
$icon.css('transform', isExpanded ? 'rotate(180deg)' : '');
|
||||||
|
|
||||||
// Handle click events
|
// Handle click events
|
||||||
$button.on('click', function(e) {
|
$button.on('click', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
// Toggle panel
|
|
||||||
$panel.slideToggle(200);
|
|
||||||
|
|
||||||
// Toggle state
|
// Toggle state
|
||||||
isExpanded = !isExpanded;
|
isExpanded = !isExpanded;
|
||||||
$button.attr('aria-expanded', isExpanded);
|
$button.attr('aria-expanded', isExpanded);
|
||||||
|
|
||||||
// Update icon rotation
|
// Update icon rotation
|
||||||
$icon.css('transform', isExpanded ? 'rotate(180deg)' : '');
|
$icon.css('transform', isExpanded ? 'rotate(180deg)' : '');
|
||||||
|
|
||||||
|
// Animate panel only on click
|
||||||
|
$panel.slideToggle(200);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user