Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(textfield): support character count (#1245)
- Loading branch information
Showing
7 changed files
with
68 additions
and
3 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
|
@@ -14,6 +14,7 @@ export { | |
export { | ||
Autofocus, | ||
Default, | ||
CharCounter, | ||
Dense, | ||
Disabled, | ||
Icon, | ||
|
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
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,46 @@ | ||
import { COMPONENT_NAME } from '../vwc-textfield.js'; | ||
import { | ||
textToDomToParent, | ||
waitNextTask, | ||
} from '../../../test/test-helpers.js'; | ||
import { chaiDomDiff } from '@open-wc/semantic-dom-diff'; | ||
|
||
chai.use(chaiDomDiff); | ||
|
||
describe('textfield character counter', () => { | ||
let addedElement; | ||
|
||
beforeEach(async () => { | ||
[addedElement] = textToDomToParent(` | ||
<${COMPONENT_NAME} charcounter maxlength="18"></${COMPONENT_NAME}> | ||
`); | ||
await waitNextTask(); | ||
}); | ||
|
||
afterEach(() => { | ||
addedElement.remove(); | ||
}); | ||
|
||
it('should have character counter', async () => { | ||
expect(getCharCounter(addedElement)).to.be.exist; | ||
}); | ||
|
||
it('should have character counter displaying correct count', async () => { | ||
const charCounter = getCharCounter(addedElement); | ||
|
||
const initialCharCounter = charCounter.textContent; | ||
|
||
addedElement.value = 'some value'; | ||
await waitNextTask(); | ||
|
||
const updatedCharCounter = charCounter.textContent; | ||
|
||
expect(initialCharCounter).to.equal('0 / 18'); | ||
expect(updatedCharCounter).to.equal('10 / 18'); | ||
}); | ||
}); | ||
|
||
function getCharCounter(baseElement) { | ||
return baseElement.shadowRoot.querySelector('.mdc-text-field-character-counter'); | ||
} | ||
|
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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