Skip to content
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

Delete shopping item #44

Merged
merged 10 commits into from
Aug 22, 2021
Prev Previous commit
Next Next commit
Add HTML attributes to modal functionality for accessiblity
Co-authored-by: Sheila Moore <Sherexmykes@gmail.com>
  • Loading branch information
connietran-dev and SheilaRMoore committed Aug 17, 2021
commit 008b887e31774e0ebe4466427406b50892256da2
25 changes: 21 additions & 4 deletions src/components/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const Modal = ({ showModal, handleModalClose, listId, itemId }) => {
.doc(itemId)
.delete()
.then(() => {
console.log('Document successfully deleted');
console.log(`Document ${itemId} successfully deleted`);
handleModalClose();
})
.catch((err) => {
console.error('Error removing document: ', err);
Expand All @@ -17,9 +18,25 @@ const Modal = ({ showModal, handleModalClose, listId, itemId }) => {

return (
<div className={toggleModalClassName}>
<h2>Are you sure you want to delete this item?</h2>
<button onClick={handleModalClose}>No, Cancel</button>
<button onClick={deleteItem}>Yes, Delete</button>
<div
role="alertdialog"
aria-modal="true"
aria-labelledby="dialog_label"
aria-describedby="dialog_desc"
>
<h2 id="dialog_label">Confirmation</h2>
<h3 id="dialog_desc">Are you sure you want to delete this item?</h3>
<button type="button" onClick={handleModalClose}>
No, Cancel
</button>
<button
type="button"
onClick={deleteItem}
aria-controls={`item-${itemId}`}
>
Yes, Delete
</button>
</div>
</div>
);
};
Expand Down
3 changes: 2 additions & 1 deletion src/components/ShoppingList/ShoppingList.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useEffect } from 'react';
import { useState } from 'react';
import { NavLink } from 'react-router-dom';

import firebase from 'firebase/app';
Expand Down Expand Up @@ -134,6 +134,7 @@ function ShoppingList({ listId }) {
type="button"
value={doc.id} // set button value to Firebase item to pass to Modal
onClick={handleModalOpen}
aria-controls={`item-${doc.id}`} // use 'item-' to match id in ShoppingListItem
>
Delete
</button>
Expand Down