This repository has been archived by the owner on Jan 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
#1422 Textarea enable linebreak (submitOnEnter) #1517
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
45ec349
WIP: Added textarea logic / some unittests
lookacat 37b7616
SubmitOnEnter default false, Added missing Unittests
lookacat ab84a4d
added changelog, addressed linting
lookacat 71bf440
Rename feature to enhancement for changelog
lookacat bbde37c
addressed PR issues
lookacat 6c01e9e
changed to const
lookacat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
changelog/unreleased/enhancement-textarea-configurable-enter-linebreak
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Enhancement: OcTextarea configurable Enter/Linebreak | ||
|
||
OcTextArea has now an property 'submitOnEnter'. | ||
This prop controls how the textarea should react to ENTER. | ||
|
||
https://github.com/owncloud/owncloud-design-system/issues/1422 | ||
https://github.com/owncloud/owncloud-design-system/pull/1517 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import { shallowMount } from "@vue/test-utils" | ||
import OcTextarea from "./OcTextarea.vue" | ||
|
||
const defaultProps = { | ||
label: "label", | ||
} | ||
|
||
describe("OcTextarea", () => { | ||
function getShallowWrapper(props = {}) { | ||
return shallowMount(OcTextarea, { | ||
propsData: { | ||
...defaultProps, | ||
...props, | ||
}, | ||
}) | ||
} | ||
|
||
const selectors = { | ||
textareaMessage: ".oc-textarea-message span", | ||
textArea: ".oc-textarea", | ||
} | ||
describe("id prop", () => { | ||
const wrapper = getShallowWrapper({ | ||
id: "test-textarea-id", | ||
descriptionMessage: "hello", | ||
}) | ||
it("should set provided id to the textarea", () => { | ||
expect(wrapper.find("textarea").attributes().id).toBe("test-textarea-id") | ||
}) | ||
it("should set label target for provided id", () => { | ||
expect(wrapper.find("label").attributes().for).toBe("test-textarea-id") | ||
}) | ||
it("should set message id according to provided id", () => { | ||
expect(wrapper.find(selectors.textareaMessage).attributes().id).toBe( | ||
"test-textarea-id-message" | ||
) | ||
}) | ||
}) | ||
describe("label prop", () => { | ||
it("should set provided label to the textarea", () => { | ||
const wrapper = getShallowWrapper() | ||
expect(wrapper.find("label").text()).toBe("label") | ||
}) | ||
}) | ||
describe("when a description message is provided", () => { | ||
const wrapper = getShallowWrapper({ descriptionMessage: "You should pass." }) | ||
it("should add the description class to the textarea message", () => { | ||
expect(wrapper.find(selectors.textareaMessage).attributes().class).toContain( | ||
"oc-textarea-description" | ||
) | ||
}) | ||
it("should show the description message as the input message text", () => { | ||
expect(wrapper.find(selectors.textareaMessage).text()).toBe("You should pass.") | ||
}) | ||
}) | ||
describe("when a warning message is provided", () => { | ||
const wrapper = getShallowWrapper({ warningMessage: "You may pass." }) | ||
it("should add the warning class to the textarea", () => { | ||
expect(wrapper.find("textarea").attributes().class).toContain("oc-textarea-warning") | ||
}) | ||
it("should add the warning class to the textarea message", () => { | ||
expect(wrapper.find(selectors.textareaMessage).attributes().class).toContain( | ||
"oc-textarea-warning" | ||
) | ||
}) | ||
it("should show the warning message as the textarea message text", () => { | ||
expect(wrapper.find(selectors.textareaMessage).text()).toBe("You may pass.") | ||
}) | ||
}) | ||
describe("when an error message is provided", () => { | ||
const wrapper = getShallowWrapper({ errorMessage: "You shall not pass." }) | ||
it("should add the error class to the textarea", () => { | ||
expect(wrapper.find("textarea").attributes().class).toContain("oc-textarea-danger") | ||
}) | ||
it("should add the error class to the textarea message", () => { | ||
expect(wrapper.find(selectors.textareaMessage).attributes().class).toContain( | ||
"oc-textarea-danger" | ||
) | ||
}) | ||
it("should show the error message as the textarea message text", () => { | ||
expect(wrapper.find(selectors.textareaMessage).text()).toBe("You shall not pass.") | ||
}) | ||
it("should set the input aria-invalid attribute to true", () => { | ||
expect(wrapper.find("textarea").attributes("aria-invalid")).toBe("true") | ||
}) | ||
}) | ||
describe("message priority", () => { | ||
it("should give error message top priority", () => { | ||
const wrapper = getShallowWrapper({ | ||
errorMessage: "You shall not pass.", | ||
warningMessage: "You may pass.", | ||
descriptionMessage: "Your should pass.", | ||
}) | ||
const messageEl = wrapper.find(".oc-textarea-message span") | ||
expect(messageEl.attributes().class).toBe( | ||
"oc-textarea-description oc-textarea-warning oc-textarea-danger" | ||
) | ||
expect(messageEl.text()).toBe("You shall not pass.") | ||
}) | ||
it("should give warning message priority over description message", () => { | ||
const wrapper = getShallowWrapper({ | ||
warningMessage: "You may pass.", | ||
descriptionMessage: "Your should pass.", | ||
}) | ||
const messageEl = wrapper.find(selectors.textareaMessage) | ||
expect(messageEl.attributes().class).toBe("oc-textarea-description oc-textarea-warning") | ||
expect(messageEl.text()).toBe("You may pass.") | ||
}) | ||
}) | ||
describe("input events", () => { | ||
it("should emit an input event on typing", async () => { | ||
const wrapper = getShallowWrapper() | ||
expect(wrapper.emitted().input).toBeFalsy() | ||
await wrapper.find("textarea").setValue("a") | ||
expect(wrapper.emitted().input).toBeTruthy() | ||
expect(wrapper.emitted().input[0][0]).toBe("a") | ||
}) | ||
}) | ||
describe("change events", () => { | ||
it("should emit a change event if submitOnEnter is true", async () => { | ||
const wrapper = getShallowWrapper({ submitOnEnter: true }) | ||
expect(wrapper.emitted().change).toBeFalsy() | ||
await wrapper.find("textarea").trigger("keydown.enter") | ||
expect(wrapper.emitted().change).toBeTruthy() | ||
}) | ||
it("shouldn't emit a change event if submitOnEnter is false", async () => { | ||
const wrapper = getShallowWrapper({ submitOnEnter: false }) | ||
expect(wrapper.emitted().change).toBeFalsy() | ||
await wrapper.find("textarea").trigger("keydown.enter") | ||
expect(wrapper.emitted().change).toBeFalsy() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hm.... personally in favor of not altering the event. Since
e.enterKey
doesn't exist, you could just create aconst
and use it in theif
statement, that still improves the readability a bit.I.e. like this:
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.
looks fine to me ^^