Skip to content

Instantly share code, notes, and snippets.

View cathyxz's full-sized avatar

Cathy Zhu cathyxz

View GitHub Profile

iOS restrictions re: bringing up the keyboard on programmatic focus

I can't find exact specifications on this, but it seems that iOS restricts bringing up the keyboard via programmatically focusing on <input>. It only brings up the keyboard in response to explicit user interaction.

  1. iOS focus on input field only brings up keyboard when called inside a click handler.
  2. It doesn’t work if the focus is async.

This presents a curious problem when you want to autofocus an input inside a modal or lightbox, since what you generally do is click on a button to bring up the lightbox, and then focus on the input after the lightbox has been opened. Without anything fancy, it actually works ok. The problem shows up when you try to add something fancy like a setTimeout or a promise.then(). I don't know why people would want to use a setTimeout here, but waiting for a promise is actually a pretty common use case. E.g. we try to batch dom manipulations like getting a lightbox to show up inside `requestAnimati

@cathyxz
cathyxz / amp-interactivity-links.md
Last active August 22, 2019 19:33
Code sample master sheet for AMP interactivity talk @ Chicago
@cathyxz
cathyxz / Stacktrace
Created February 23, 2018 03:06
amp validator stacktrace on travis
Failures:
1) ValidatorFeatures amp-facebook-page/0.1/test/validator-amp-facebook-page.html
Message:
AssertionError:
amp-facebook-page/0.1/test/validator-amp-facebook-page.out:1:0
expected:
PASS
| <!--
| Copyright 2018 The AMP HTML Authors. All Rights Reserved.
|
@cathyxz
cathyxz / countries.json
Last active December 19, 2017 23:33
Country Names in Json
{
"items": [{
"name": "Afghanistan",
"code": "AF"
},
{
"name": "land Islands",
"code": "AX"
}
]
@cathyxz
cathyxz / pre-commit
Created January 26, 2017 04:44
Pre-commit hook to reject commit if you have added console.logs
#!/bin/sh
count=`git diff HEAD | grep '+.*console\.log' | wc -l | awk '{print $1}'`
if [[ "$count" -ge 1 ]]; then
echo "Please remove console.log() statements from your changes before committing."
echo "Refusing to commit changes."
git diff HEAD | grep '+.*console\.log'
exit 1
fi
@cathyxz
cathyxz / prepare-commit-msg
Last active January 24, 2017 07:49
verify release merge
#!/bin/sh
# Pre-merge hook that lists all commits and asks you if you really want to
# merge them in. For release branches only.
case $2 in
merge)
branch=$(grep -o "release/[0-9]\.[0-9]" $1)
if [[ ! -z $branch ]]
then
// Scraping Made Easy with jQuery and SelectorGadget
// (http://blog.dtrejo.com/scraping-made-easy-with-jquery-and-selectorga)
// by David Trejo
//
// Install node.js and npm:
// http://joyeur.com/2010/12/10/installing-node-and-npm/
// Then run
// npm install jsdom jquery http-agent
// node numresults.js
//