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

Custom pagination boundary and directional link text #899

Closed
forrestab opened this issue Oct 17, 2016 · 19 comments
Closed

Custom pagination boundary and directional link text #899

forrestab opened this issue Oct 17, 2016 · 19 comments

Comments

@forrestab
Copy link

In the pagination component I would like to use the words, First, Previous, Next and Last as the boundary and directional link text. However, I am unable to find any settings related to changing the shown text on these links.

When looking at the component template I see:

<a aria-label="First" class="page-link" href>
    <span aria-hidden="true">&laquo;</span>
    <span class="sr-only">First</span>
</a>

And I notice an .sr-only class is on the text I want shown. As a work around I can handle this in css, but I am unable to remove the .sr-only class from the element which makes the generated html unclear.

In the previous pagination component in bootstrap-ui (for angular 1.x) we were given settings to customize the boundary and directional link texts.

  • first-text
  • last-text
  • next-text
  • previous-text

Could we get these settings added or am I missing something and there is a better work around?

angular: 2.0.1
ng-bootstrap: 1.0.0-alpha.7
bootstrap: 4.0.0-alpha.4

@pkozlowski-opensource
Copy link
Member

@forrestab we don't support customization of text / markup displayed on boundary links, although it is on our roadmap (not the high priority atm, though).

Regarding elements with the sr-only class - those are meant to be used by screen readers so you definitively don't want to remove / alter them if you care about accessibility (and as any web developer, you should).

@forrestab
Copy link
Author

forrestab commented Oct 17, 2016

@pkozlowski-opensource glad its on the roadmap, however, I believed you may have jumped to a conclusion about me and my sr-only work around comment. As a developer I do care about accessibility.

My work around proposal is simply to show what the sr-only class is hiding and hide the arrows. I would prefer to show actual words instead of leaving it up to a user to determine what an icon does. This should not effect screen readers or accessibility. (I of course would not break the sr-only class for all of bootstrap, just the pagination component)

Do you or anyone else see an issue with this work around?

@wesleycho
Copy link
Member

@pkozlowski-opensource maybe it would be worth using slots with ng-content here to allow custom content. This would have low overhead to implement I think, and allow full customization without having to add a binding.

@intellix
Copy link
Contributor

intellix commented Apr 22, 2017

Just to add another use-case; I want to add custom icons/html instead using SVG icons which go with a design we received:

<i class="icon icon-left-triangle" inlineSVG="left-triangle.svg"></i>

And I imagine it likely that people will want to add font icons there:

<i class="fa fa-chevron-left"></i>

@maxpark-jd
Copy link

Since last November: alex7olaru@f7ca921
Will this ever be merged?

@khdevnet
Copy link

You can put any text in directional links with css add something like css below
a[aria-label] { span { display: none; } &:after { content: attr(aria-label); } }

instead attr(area-label) add text what you want, and also add css rules :nth-child() to specify specific element

ExFlo added a commit to ExFlo/ng-boostrap that referenced this issue Aug 7, 2018
ExFlo added a commit to ExFlo/ng-boostrap that referenced this issue Aug 7, 2018
ExFlo added a commit to ExFlo/ng-boostrap that referenced this issue Aug 7, 2018
ExFlo added a commit to ExFlo/ng-boostrap that referenced this issue Aug 7, 2018
@michaeljota
Copy link
Contributor

I'm requiring this, and I think I figure a nice way to implement this:

Currently, the anchors are being created hard wired:

      <li *ngIf="directionLinks" class="page-item"
        [class.disabled]="!hasPrevious() || disabled">
        <a aria-label="Previous" i18n-aria-label="@@ngb.pagination.previous-aria" class="page-link" href
          (click)="selectPage(page-1); $event.preventDefault()" [attr.tabindex]="(hasPrevious() ? null : '-1')">
          <span aria-hidden="true" i18n="@@ngb.pagination.previous">&laquo;</span>
        </a>
      </li>

As it was said, the best way to do this properly is to do it by content projection. However, there is not currently a way to be able to react if the content is empty. However, it has been requested and in the issue you can find some interesting workarounds.

Like this one:

<div class="my-custom-component-content-wrapper">
    <ng-content select="my-custom-component"></ng-content>
</div>
<my-custom-component>
    This shows something default.
</my-custom-component>
.my-custom-component-content-wrapper:not(:empty) + my-custom-component {
    display: none;
}

So, this could be applied to pagination.

<li
  *ngIf="directionLinks"
  class="page-item"
  [class.disabled]="!hasPrevious() || disabled"
>
  <a
    aria-label="Previous"
    i18n-aria-label="@@ngb.pagination.previous-aria"
    class="page-link"
    href
    (click)="selectPage(page - 1); $event.preventDefault()"
    [attr.tabindex]="hasPrevious() ? null : '-1'"
  >
    <span class="page-anchor"><ng-content select="previous"></ng-content></span>
    <span aria-hidden="true" i18n="@@ngb.pagination.previous">&laquo;</span>
  </a>
</li>
  .page-anchor:emtpy {
    display: none;
  }
  .page-anchor:not(:empty) + span[aria-hidden="true"] {
    display: none;
  }

And could be used, like this:

<ngb-pagination>
  <span previous>Prev</span>
</ngb-pagination>

This wouldn't break any existent code, and would allow the usage of custom templates for the icon, including, the usage of FontAwesome's fa-icon component.

@ryanbowden
Copy link

Any update of this happening? We really need this for our project.

@varnastadeus
Copy link

varnastadeus commented Jan 14, 2019

this can be achieved partially by using css and custom fonts, eg.:

ngb-pagination li {
    &:first-child a {
        span {
            display: none;
        }
        &:before {
            content: "\F141";
            font: normal normal normal 24px/1 "Material Design Icons";
        }
    }
}

this will override first link with chevron from Material Design Icons.
screenshot 2019-01-14 at 16 28 01

@ryanbowden
Copy link

Well we want the words Next and Previous and that css fix does not really work for translations either.

maxokorokov added a commit to maxokorokov/ng-bootstrap that referenced this issue Jan 16, 2019
Provides templates for all pagination links to override the markup

Fixes ng-bootstrap#899
@maxokorokov maxokorokov added this to the 4.1 milestone Jan 16, 2019
@maxokorokov
Copy link
Member

Could the interested people please take a look at #2971 and check if there are use case that won't be covered by this approach?

@michaeljota
Copy link
Contributor

@maxokorokov Thanks! I would have to try it, but seems that it covers all the expected scenarios.

maxokorokov added a commit to maxokorokov/ng-bootstrap that referenced this issue Feb 12, 2019
Provides templates for all pagination links to override the markup

Fixes ng-bootstrap#899
maxokorokov added a commit that referenced this issue Feb 12, 2019
Provides templates for all pagination links to override the markup

Fixes #899
@p-maron
Copy link

p-maron commented Mar 24, 2019

Based on varnastadeus's comment, the following worked for me to change the pagination links to words. Thanks @varnastadeus.

::ng-deep ngb-pagination ul > li {
&:first-child a {
span {
display: none;
}
&:before {
content: "Previous";
font-size: 13px;
font-weight: 600;
}
}
&:last-child a {
span {
display: none;
}
&:before {
content: "Next";
font-size: 13px;
font-weight: 600;
}
}
}

@mendeza
Copy link

mendeza commented Mar 25, 2019

@p-maron, if you ever need to localize this site/app to a non-English language, this solution might need reconsideration.

@p-maron
Copy link

p-maron commented Apr 10, 2019

@mendeza Oh, do you mean because of the hard coded content entries?

@mendeza
Copy link

mendeza commented Apr 10, 2019

Yes

@p-maron
Copy link

p-maron commented Apr 10, 2019

Any suggestions?

@mendeza
Copy link

mendeza commented Apr 10, 2019

Well, isn't this a moot point as of 4.1.0? See "Using Templates."

@kcsattiraju
Copy link

kcsattiraju commented Jul 24, 2019

I want to remove the directional link if it a first page or a last page since the UX design thinks that it is quiet confusing . I am struggling with the code . Any suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests