Skip to content

Commit

Permalink
#5 c29a923 79d3f5f
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmhunt committed Dec 16, 2017
1 parent 6cc40eb commit be67572
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Expand Up @@ -27,7 +27,7 @@ describe('Binding: Visible', function () {
provider.bindingHandlers.set(coreBindings)
})

it('Should display the node only when the value is true', function () {
it('Visible means the node only when the value is true', function () {
var myObservable = observable(false)
testNode.innerHTML = "<input data-bind='visible:myModelProperty()' />"
applyBindings({
Expand All @@ -39,7 +39,7 @@ describe('Binding: Visible', function () {
expect(testNode.childNodes[0].style.display).toEqual('')
})

it('Should unwrap observables implicitly', function () {
it('Visible should unwrap observables implicitly', function () {
var myObservable = observable(false)
testNode.innerHTML = "<input data-bind='visible:myModelProperty' />"
applyBindings({
Expand Down
10 changes: 7 additions & 3 deletions packages/tko.binding.core/src/visible.js
Expand Up @@ -5,13 +5,17 @@ import {
export var visible = {
update: function (element, valueAccessor) {
var value = unwrap(valueAccessor())
var isCurrentlyVisible = !(element.style.display == 'none')
if (value && !isCurrentlyVisible) { element.style.display = '' } else if ((!value) && isCurrentlyVisible) { element.style.display = 'none' }
var isCurrentlyVisible = !(element.style.display === 'none')
if (value && !isCurrentlyVisible) {
element.style.display = ''
} else if (!value && isCurrentlyVisible) {
element.style.display = 'none'
}
}
}

export var hidden = {
update: function (element, valueAccessor) {
visible.update.call(this, element, function () { return !unwrap(valueAccessor()) })
visible.update.call(this, element, () => !unwrap(valueAccessor()))
}
}

0 comments on commit be67572

Please sign in to comment.