Skip to content

Commit

Permalink
fix(fade): add d-none by default for fade steppers
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann-S committed Oct 15, 2018
1 parent a84b5d7 commit cb4a14d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Add the following HTML:
</div>
```

If you want to add a `fade` animation, add `.fade` class on your `.content`.
If you want to add a `fade` animation, add `.fade` and `.d-none` classes on your `.content`.

### JavaScript

Expand Down
6 changes: 3 additions & 3 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,21 @@ <h3>Non linear stepper (with fade)</h3>
</div>
<div class="bs-stepper-content">
<form onSubmit="return false">
<div id="test-nlf-1" class="content fade">
<div id="test-nlf-1" class="content fade d-none">
<div class="form-group">
<label for="exampleInputName2">Name</label>
<input type="email" class="form-control" id="exampleInputName2" placeholder="Enter your name">
</div>
<button class="btn btn-primary" onclick="stepper3.next()">Next</button>
</div>
<div id="test-nlf-2" class="content fade">
<div id="test-nlf-2" class="content fade d-none">
<div class="form-group">
<label for="exampleInpuAddress2">Address</label>
<input type="email" class="form-control" id="exampleInpuAddress2" placeholder="Enter your address">
</div>
<button class="btn btn-primary" onclick="stepper3.next()">Next</button>
</div>
<div id="test-nlf-3" class="content fade text-center">
<div id="test-nlf-3" class="content fade d-none text-center">
<button type="submit" class="btn btn-primary mt-5">Submit</button>
</div>
</form>
Expand Down
15 changes: 7 additions & 8 deletions src/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ const showContent = (content, contentList) => {
return
}

function complete () {
content.classList.add(ClassName.BLOCK)
content.removeEventListener(transitionEndEvent, complete)
}

const activeContent = contentList.filter(content => content.classList.contains(ClassName.ACTIVE))
if (activeContent.length) {
activeContent[0].classList.remove(ClassName.ACTIVE)
Expand All @@ -44,12 +49,6 @@ const showContent = (content, contentList) => {

if (content.classList.contains(ClassName.FADE)) {
content.classList.remove(ClassName.NONE)

function complete() {
content.classList.add(ClassName.BLOCK)
content.removeEventListener(transitionEndEvent, complete)
}

const duration = getTransitionDurationFromElement(content)
content.addEventListener(transitionEndEvent, complete)
if (activeContent.length) {
Expand Down Expand Up @@ -87,7 +86,7 @@ const emulateTransitionEnd = (element, duration) => {
let called = false
const durationPadding = 5
const emulatedDuration = duration + durationPadding
function listener() {
function listener () {
called = true
element.removeEventListener(transitionEndEvent, listener)
}
Expand All @@ -114,5 +113,5 @@ export {
Selectors,
ClassName,
customProperty,
detectFade,
detectFade
}
6 changes: 3 additions & 3 deletions tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ <h2>Linear stepper</h2>
</div>
</div>
<div class="bs-stepper-content">
<div id="test-l-1" class="content fade">
<div id="test-l-1" class="content fade d-none">
<p class="text-center">test 1</p>
<button class="btn btn-primary" onclick="stepper1.next()">Next</button>
</div>
<div id="test-l-2" class="content fade">
<div id="test-l-2" class="content fade d-none">
<p class="text-center">test 2</p>
<button class="btn btn-primary" onclick="stepper1.next()">Next</button>
</div>
<div id="test-l-3" class="content fade">
<div id="test-l-3" class="content fade d-none">
<p class="text-center">test 3</p>
<button class="btn btn-primary" onclick="stepper1.next()">Next</button>
<button class="btn btn-primary" onclick="stepper1.previous()">Previous</button>
Expand Down

0 comments on commit cb4a14d

Please sign in to comment.