Skip to content
An input element that sends its value to a server endpoint and renders the response body.
Branch: master
Clone or download
Latest commit 2b899d0 Jul 24, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples Change example initial state May 10, 2019
test Update development dependencies May 24, 2019
.babelrc Initial commit Apr 30, 2019
.eslintrc.json Initial commit Apr 30, 2019
.flowconfig Initial commit Apr 30, 2019
.gitignore Initial commit Apr 30, 2019
.travis.yml Initial commit Apr 30, 2019
LICENSE Update element name Apr 30, 2019
README.md Document [param] May 13, 2019
index.js Set same-origin as default Jun 6, 2019
index.js.flow Simplify API, rename name attribute May 13, 2019
package-lock.json 0.0.4 Jul 24, 2019
package.json 0.0.4 Jul 24, 2019
prettier.config.js Use github-lint May 10, 2019

README.md

<remote-input> element

An input element that sends its value to a server endpoint and renders the response body.

Installation

$ npm install @github/remote-input-element

Usage

import '@github/remote-input-element'
<!-- Filter a list of items from the server -->
<remote-input src="/query" aria-owns="results">
  <input>
</remote-input>
<ul id="results"></ul>

A GET request will be sent to /query?q=${input.value}.

The parameter name (q) is customizable with the [param] attribute:

<!-- Live preview of Markdown -->
<remote-input src="/preview" aria-owns="md-preview" param="body">
  <textarea></textarea>
</remote-input>
<div id="md-preview"></div>

Styling loading state

A boolean [loading] attribute is added to <remote-input> when a network request begins and removed when it ends.

.loading-icon { display: none; }
remote-input[loading] .loading-icon { display: inline; }

Events

const remoteInput = document.querySelector('remote-input')

// Network request lifecycle events.
remoteInput.addEventListener('loadstart', function(event) {
  console.log('Network request started', event)
})
remoteInput.addEventListener('loadend', function(event) {
  console.log('Network request complete', event)
})
remoteInput.addEventListener('load', function(event) {
  console.log('Network request succeeded', event)
})
remoteInput.addEventListener('error', function(event) {
  console.log('Network request failed', event)
})

Browser support

Browsers without native custom element support require a polyfill.

  • Chrome
  • Firefox
  • Safari
  • Microsoft Edge

Development

npm install
npm test

License

Distributed under the MIT license. See LICENSE for details.

You can’t perform that action at this time.