Fix initial panel state handling to prevent yoyo effect on first load

This commit is contained in:
Marcus Quinn
2025-03-16 02:16:26 +00:00
parent c126003d45
commit 2db85d559b

View File

@ -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);
}); });
}); });
}); });