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

Active State after 'openOnInit' #58

Closed
marianohsn opened this issue Feb 21, 2023 · 3 comments
Closed

Active State after 'openOnInit' #58

marianohsn opened this issue Feb 21, 2023 · 3 comments
Labels
question Further information is requested

Comments

@marianohsn
Copy link

I'm passing the option: openOnInit: [2] in order to show the third accordion item expanded by default, but its corresponding header/button's style remains in collapsed state.

How can I make the header style change accordingly to expanded state when using openOnInit: []?

Incorrect state of third header after being triggered by openOnInit: [2]:
Screen Shot 2023-02-21 at 10 58 21 AM

Correct state of third header after being triggered by user click:
Screen Shot 2023-02-21 at 10 58 28 AM

@michu2k
Copy link
Owner

michu2k commented Feb 22, 2023

Hi @marianohsn
The applied styles are correct. The difference between the first and second images is that the :focus styles are applied to the second image because the element clicked is focused.

    .ac-trigger:focus {
      color: $color-grey;
    }

If you want to apply styles also when the element is active, you need to edit this fragment:

  &.is-active {
    .ac-panel {
      visibility: visible;
    }

    & > .ac-header .ac-trigger {
      // TRIGGER STYLES   <--

      &::after {
        content: '\2013';
      }
    }
  }

@michu2k michu2k added the question Further information is requested label Feb 22, 2023
@marianohsn
Copy link
Author

Hello @michu2k - Thank you for your reply

Shouldn't the openOnInit: [X] function also change the corresponding header/button to its focused state when triggered? I assumed that woud be the logical behaviour.

Otherwise, I could try simulating a click, or altering the style of the expanded header via JS.

@michu2k
Copy link
Owner

michu2k commented Feb 22, 2023

I checked the official W3 accordion demo and it looks like they are doing exactly the same, applying styles to the currently focused element. I would say that using the same styles for the focus state and the open state can be a bit confusing for someone who uses Tab for navigation.

Otherwise, I could try simulating a click, or altering the style of the expanded header via JS.

You can just add an additional className and manage the styles via CSS or modify activeClass property.

@michu2k michu2k closed this as completed Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants