Skip to content

Commit

Permalink
onclick focus
Browse files Browse the repository at this point in the history
  • Loading branch information
caseykennedy committed Oct 19, 2020
1 parent f48ba73 commit 725b4a8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
15 changes: 15 additions & 0 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"babel-plugin-styled-components": "^1.10.7",
"body-scroll-lock": "^3.1.5",
"dotenv": "^8.2.0",
"focus-trap": "^6.1.3",
"framer-motion": "^2.7.6",
"gatsby": "^2.20.7",
"gatsby-image": "^2.3.1",
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/Cart/Cart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const Cart: React.FC<Props> = ({ mainRef }) => {
const [hasItems, quantity] = useQuantity()
return (
<>
<FocusLock>
<FocusLock persistentFocus={false}>
<S.Cart
className={`cart ${isCartOpen ? 'cart--open' : 'cart--closed'}`}
id="cart"
Expand Down
17 changes: 11 additions & 6 deletions web/src/components/Cart/LineItem/LineItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ import StoreContext from '../../../context/StoreContext'

const LineItem: React.FC<{ item: LineItem }> = ({ item }) => {
const qtyRef = React.useRef<HTMLInputElement>(null)
// const element = qtyRef.current
// if (null !== element) {
// element.focus({
// preventScroll: true
// })
// }

const {
removeLineItem,
Expand All @@ -48,6 +42,16 @@ const LineItem: React.FC<{ item: LineItem }> = ({ item }) => {
updateLineItem(client, checkout.id, item.id, quantity)
}

const focusInput = () => {
const element = qtyRef.current
if (null !== element) {
element.focus({
preventScroll: true
})
console.log('e clicked')
}
}

// const handleTouch = (e: Event) => {
// e.preventDefault()
// }
Expand Down Expand Up @@ -141,6 +145,7 @@ const LineItem: React.FC<{ item: LineItem }> = ({ item }) => {
onChange={handleQuantityChange}
value={quantity}
ref={qtyRef}
onClick={focusInput}
/>
<button
className="btn-update"
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/Cart/styles.scss.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const Cart = styled(Box)`
opacity: 0;
visibility: hidden;
position: absolute;
position: fixed;
/* top: 0; */
right: 0;
bottom: 0;
Expand Down

0 comments on commit 725b4a8

Please sign in to comment.