Skip to content

Add a new part(s) or element(s) for customizing navigation buttons #7467

Open
@jpierson-at-riis

Description

@jpierson-at-riis

Clear and concise description of the problem

As a developer using Swiper element I want to have a simpler way to override the icon and visualization of the included navigation buttons so that I do not have to create custom next and previous buttons.

Suggested solution

Introduce a new part or set of two parts to the parts supported for Swiper Element.

Single part for both:

  • navigation-svg

or

Two separate parts:

  • button-prev-svg
  • button-next-svg

Alternative

Pseudo selectors and attribute selectors on existing parts

Alternative approaches attempted do not suffice apparently due to how ::part works.

/* Attempt using attribute selector */
swiper-container::part(button-prev)[aria-disabled=true],
swiper-container::part(button-next)[aria-disabled=true] {
  display: none;
}

/* Attempt using attribute selector */
swiper-container::part(button-prev).swiper-button-disabled,
swiper-container::part(button-next).swiper-button-disabled {
  display: none;
}

Additional custom elements for navigation buttons

Another alternative solution could be to introduce separate child elements <swiper-button-prev> and <swiper-button-next> which could be similar to how <swiper-slide> works in that the developer can provide their own implementations as children of the swiper-component element in order to provide the markup for the buttons to be used. While this may be the more extensible and elegant option I'm not sure of the limitations of web components myself and whether it is possible to have multiple custom components as children in the same what that swiper-slide currently works so my preferred proposal would be to expose the additional parts for overriding styles as a simpler initial approach.

Additional context

See discussion linked below. There are at least five examples that I've come across so far of developers running into the limits of what can be done with the built in Navigation CSS properties and the Navigation button parts and I think that improving this area of the component will help to reduce how much custom code is needed when adopting Swiper in many cases.

#4348

Validations

  • Follow our Code of Conduct
  • Read the docs.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.

Would you like to open a PR for this feature?

  • I'm willing to open a PR

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions