-
Notifications
You must be signed in to change notification settings - Fork 15
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
#351 Inline editable enchancements #366
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,8 @@ | |
.hx-input-group { | ||
margin: -0.45em 0; | ||
} | ||
} | ||
|
||
.hx-inline-editable-no-value { | ||
font-style: italic; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Making it italic when no value has been entered is probably enough of a visual cue (along with the |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,165 @@ | ||
describe 'inline-editable', -> | ||
# ... | ||
fixture = undefined | ||
|
||
before -> | ||
fixture = hx.detached('div') | ||
hx.select('body').add(fixture) | ||
|
||
beforeEach -> | ||
fixture.clear() | ||
|
||
after -> | ||
fixture.remove() | ||
|
||
it 'should have user facing text defined', -> | ||
hx.userFacingText('inlineEditable', 'enterValue').should.equal('Enter Value') | ||
|
||
it 'should use the text of the selection used to create it as the value', -> | ||
container = fixture.append('div').text('test') | ||
ie = new hx.InlineEditable(container.node()) | ||
ie.value().should.equal('test') | ||
|
||
it 'should correctly set the input value', -> | ||
container = fixture.append('div').text('test') | ||
ie = new hx.InlineEditable(container.node()) | ||
input = container.select('.hx-name') | ||
input.value().should.equal('') | ||
testHelpers.fakeNodeEvent(container.select('.hx-morph-toggle').node())() | ||
input.value().should.equal('test') | ||
|
||
it 'should use the value option correctly', -> | ||
container = fixture.append('div').text('test') | ||
ie = new hx.InlineEditable(container.node(), { | ||
value: 'Dave' | ||
}) | ||
ie.value().should.equal('Dave') | ||
|
||
it 'should emit the change event when the value is updated using the api', -> | ||
container = fixture.append('div') | ||
ie = new hx.InlineEditable(container.node()) | ||
spy = chai.spy() | ||
ie.on 'change', spy | ||
ie.value('test') | ||
spy.should.have.been.called.with({ | ||
cause: 'api', | ||
value: 'test' | ||
}) | ||
|
||
it 'should emit the change event when the value is updated', -> | ||
container = fixture.append('div') | ||
ie = new hx.InlineEditable(container.node()) | ||
spy = chai.spy() | ||
ie.on 'change', spy | ||
input = container.select('.hx-name') | ||
testHelpers.fakeNodeEvent(container.select('.hx-morph-toggle').node())() | ||
input.value('bob') | ||
testHelpers.fakeNodeEvent(container.select('.hx-confirm').node())() | ||
spy.should.have.been.called.with({ | ||
cause: 'user', | ||
value: 'bob' | ||
}) | ||
|
||
it 'should show and focus the input when clicked', -> | ||
container = fixture.append('div') | ||
ie = new hx.InlineEditable(container.node()) | ||
input = container.select('.hx-name').node() | ||
content = container.select('.hx-morph-content') | ||
input.should.not.equal(document.activeElement) | ||
content.style('display').should.equal('none') | ||
testHelpers.fakeNodeEvent(container.select('.hx-morph-toggle').node())() | ||
input.should.equal(document.activeElement) | ||
content.style('display').should.equal('block') | ||
|
||
it 'should show the enterValueText when no value is provided', -> | ||
container = fixture.append('div') | ||
ie = new hx.InlineEditable(container.node()) | ||
container.text().should.equal('Enter Value') | ||
|
||
it 'should use the provided enterValueText', -> | ||
container = fixture.append('div') | ||
ie = new hx.InlineEditable(container.node(), { | ||
enterValueText: 'Bob' | ||
}) | ||
container.text().should.equal('Bob') | ||
|
||
it 'should show the enterValueText when the value is cleared', -> | ||
container = fixture.append('div').text('test') | ||
ie = new hx.InlineEditable(container.node()) | ||
input = container.select('.hx-name') | ||
testHelpers.fakeNodeEvent(container.select('.hx-morph-toggle').node())() | ||
input.value('') | ||
testHelpers.fakeNodeEvent(container.select('.hx-confirm').node())() | ||
container.text().should.equal('Enter Value') | ||
|
||
it 'should set the value when enter is pressed', -> | ||
container = fixture.append('div') | ||
ie = new hx.InlineEditable(container.node()) | ||
spy = chai.spy() | ||
ie.on 'change', spy | ||
input = container.select('.hx-name') | ||
testHelpers.fakeNodeEvent(container.select('.hx-morph-toggle').node())() | ||
input.value('bob') | ||
testHelpers.fakeNodeEvent(input.node(), 'keydown')({ key: 'Enter' }) | ||
spy.should.have.been.called.with({ | ||
cause: 'user', | ||
value: 'bob' | ||
}) | ||
|
||
it 'should support deprecated event values', -> | ||
container = fixture.append('div') | ||
ie = new hx.InlineEditable(container.node()) | ||
spy = chai.spy() | ||
ie.on 'change', spy | ||
input = container.select('.hx-name') | ||
testHelpers.fakeNodeEvent(container.select('.hx-morph-toggle').node())() | ||
input.value('bob') | ||
testHelpers.fakeNodeEvent(input.node(), 'keydown')({ keyCode: 13 }) | ||
spy.should.have.been.called.with({ | ||
cause: 'user', | ||
value: 'bob' | ||
}) | ||
testHelpers.fakeNodeEvent(container.select('.hx-morph-toggle').node())() | ||
input.value('steve') | ||
testHelpers.fakeNodeEvent(input.node(), 'keydown')({ which: 13 }) | ||
spy.should.have.been.called.with({ | ||
cause: 'user', | ||
value: 'steve' | ||
}) | ||
|
||
it 'should allow the user to enter text', -> | ||
container = fixture.append('div') | ||
ie = new hx.InlineEditable(container.node()) | ||
spy = chai.spy() | ||
ie.on 'change', spy | ||
input = container.select('.hx-name') | ||
testHelpers.fakeNodeEvent(container.select('.hx-morph-toggle').node())() | ||
input.value('bob') | ||
testHelpers.fakeNodeEvent(input.node(), 'keydown')({}) | ||
spy.should.not.have.been.called() | ||
|
||
it 'should show the enterValueText when the value is cleared', -> | ||
container = fixture.append('div').text('test') | ||
ie = new hx.InlineEditable(container.node(), { | ||
enterValueText: 'Bob' | ||
}) | ||
input = container.select('.hx-name') | ||
testHelpers.fakeNodeEvent(container.select('.hx-morph-toggle').node())() | ||
input.value('') | ||
testHelpers.fakeNodeEvent(container.select('.hx-confirm').node())() | ||
container.text().should.equal('Bob') | ||
|
||
describe 'fluid', -> | ||
it 'should return a selection', -> | ||
(hx.inlineEditable() instanceof hx.Selection).should.equal(true) | ||
|
||
it 'should use the value option', -> | ||
ie = hx.inlineEditable({ | ||
value: 'Bob' | ||
}) | ||
ie.api().value().should.equal('Bob') | ||
|
||
it 'should use the enterValueText option', -> | ||
ie = hx.inlineEditable({ | ||
value: 'Bob' | ||
}) | ||
ie.api().value().should.equal('Bob') |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,7 @@ class InlineMorphSection extends MorphSection | |
morphSection.detector = undefined | ||
morphSection.hide() | ||
@on 'hide', 'hx.morph-section', (data) -> | ||
exitEditMode.call(morphSection, data.toggle, data.content) | ||
exitEditMode?.call(morphSection, data.toggle, data.content) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So you don't have to pass it through as an empty function if you don't have an exit edit mode function |
||
hx.select(data.toggle).style('display', '') | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was broken anyway (api was always passed as false) so I updated to the cause/value mentality.