Skip to content

Commit

Permalink
delete button
Browse files Browse the repository at this point in the history
  • Loading branch information
rinaok committed Mar 10, 2024
1 parent a5f5cd9 commit e92197f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
12 changes: 1 addition & 11 deletions libs/components/src/lib/dial-pad/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,4 @@ You can change the error text with the `error-text` attribute.
| `blur` | Emitted from the input element |
| `focus` | Emitted from the input element |

</div>



## Accessibility

- The input element should have aria-label, if no visible label is in the design
- The dial / end call buttons should have an aria-label, if it is designed to just show an icon only
- The feedback-text area should have aria-live set to polite, so that it is read out by screen readers when it changes
- Keyboard only users will navigate the buttons and input using the TAB key

</div>
20 changes: 20 additions & 0 deletions libs/components/src/lib/dial-pad/dial-pad.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ describe('vwc-dial-pad', () => {
return digits?.querySelectorAll('vwc-button') as NodeListOf<Button>;
}

function getDeleteButton() {
return getTextField().querySelector('vwc-button') as Button;
}

beforeEach(async () => {
element = (await fixture(
`<${COMPONENT_TAG}></${COMPONENT_TAG}>`
Expand Down Expand Up @@ -68,6 +72,22 @@ describe('vwc-dial-pad', () => {
});
});

describe('delete', function () {
it('should show delete button when text field has value', async function () {
element.value = '123';
await elementUpdated(element);
expect(getDeleteButton()).not.toBeNull();
});

it('should remove last character from text field when clicked on delete button', async function () {
element.value = '123';
await elementUpdated(element);
getDeleteButton().click();
await elementUpdated(element);
expect(getTextField().value).toEqual('12');
});
});

describe('keypad-click', function () {
it('should fire keypad-click event when clicked on keypad', async function () {
const spy = jest.fn();
Expand Down
2 changes: 1 addition & 1 deletion libs/components/src/lib/dial-pad/dial-pad.template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function renderTextField(textFieldTag: string, buttonTag: string) {
@keydown="${(x, c) => handleKeyDown(x, c.event as KeyboardEvent)}">
${when(x => (x.value?.length && x.value?.length > 0), html`<${buttonTag}
slot="action-items" size='condensed' icon="backspace-line" aria-label="${x => x.deleteAriaLabel || x.locale.dialPad.deleteLabel}"
appearance='ghost' ?disabled="${x => x.disabled}" @click="${x => x.clearField()}">
appearance='ghost' ?disabled="${x => x.disabled}" @click="${x => x.deleteLastCharacter()}">
</${buttonTag}>`)}
</${textFieldTag}>`;
}
Expand Down
4 changes: 2 additions & 2 deletions libs/components/src/lib/dial-pad/dial-pad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ export class DialPad extends FoundationElement {
*
* @internal
*/
clearField = () => {
this.value = '';
deleteLastCharacter = () => {
this.value = this.value.slice(0, -1);
};

/**
Expand Down

0 comments on commit e92197f

Please sign in to comment.