Skip to content

Commit

Permalink
feat: add focus option to Slider component
Browse files Browse the repository at this point in the history
  • Loading branch information
janschoenherr committed Feb 20, 2024
1 parent 9f3ec94 commit ae16f4d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Added

- Add breakpoint classes for flex vertical alignment
- Add `active` option to Slider component

### Fixed

Expand Down
12 changes: 11 additions & 1 deletion src/js/components/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default {
props: {
center: Boolean,
sets: Boolean,
active: String,
},

data: {
Expand All @@ -42,6 +43,7 @@ export default {
selList: '.uk-slider-items',
selNav: '.uk-slider-nav',
clsContainer: 'uk-slider-container',
active: 'all',
Transitioner,
},

Expand Down Expand Up @@ -235,7 +237,15 @@ export default {
},

updateActiveClasses(currentIndex = this.index) {
const actives = this._getTransitioner(currentIndex).getActives();
let actives = this._getTransitioner(currentIndex).getActives();

if (this.active !== 'all') {
let index = currentIndex;
if (this.active === 'center') {
index += Math.ceil(actives.length / 2) - 1;
}
actives = [this.slides[this.getValidIndex(index)]];
}

const activeClasses = [
this.clsActive,
Expand Down
13 changes: 12 additions & 1 deletion tests/slider.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ <h1>Slider</h1>
<option value="0">Single</option>
<option value="1">Sets</option>
</select>
<select id="js-active-switcher" class="uk-select uk-form-width-small" aria-label="Active switcher">
<option value="">All</option>
<option value="first">First</option>
<option value="center">Center</option>
</select>
</div>

<h2>Content Widths</h2>
Expand Down Expand Up @@ -577,6 +582,12 @@ <h2>JavaScript Options</h2>
<td>0</td>
<td>Slider item to show. 0 based index.</td>
</tr>
<tr>
<td><code>active</code></td>
<td>String</td>
<td>all</td>
<td>Slider item/items to apply the transition active class to. (all|first|center)</td>
</tr>
<tr>
<td><code>pause-on-hover</code></td>
<td>Boolean</td>
Expand Down Expand Up @@ -646,7 +657,7 @@ <h2>i18n</h2>
<script>

const {attr, $$, on} = UIkit.util;
for (const attribute of ['finite', 'center', 'sets']) {
for (const attribute of ['finite', 'center', 'sets', 'active']) {
on(`#js-${attribute}-switcher`, 'change', e =>
attr($$('[uk-slider]'), attribute, e.target.value)
);
Expand Down

0 comments on commit ae16f4d

Please sign in to comment.