Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="description">
  <h1>Input Auto-Complete</h1>
  <div>Try typing in "design"</div>

</div>

<div class="input-field" ng-class="{focus:isFocused}" ng-app="SuggestedQuery" ng-controller="suggestionInputCtrl as main" ng-click="editInput()">
  <div class='editable' ng-focus='isFocused = true;' contenteditable ng-model="inputQuery"></div><div class="suggested noselect">{{suggestedQuery}}</div>
</div>
              
            
!

CSS

              
                @import "compass/css3";
@import url(https://fonts.googleapis.com/css?family=Open+Sans:400,300);
.noselect {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.description {
  text-align: center;
  color: white;
  margin-bottom: 50px;
}
h1 {
  font-weight: 300;
  color: white;
}

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  background-color: rgb(109, 109, 194);
  display: flex;
  flex-direction: column;
  align-items: center;
  font-family: "Open Sans", sans-serif;
  justify-content: center;

}

.input-field {
  position: relative;
  @include transition(all 0.25s ease-in-out);
  height: 5vw;
  width: 70%;
  background-color: whitesmoke;
  padding: .5vw;
  box-sizing: border-box;
  border: 1px solid #DDDDDD;
  border-radius: 3px;
  .editable, .suggested {
    display: inline-block;
    /* border: 1px solid black; */
    font-size: 2.5vw;
    margin: 0;
    padding: 0;
  }
  .editable {
    background-color: transparent;
    outline: none;
    min-width: 1px;
  }
  .suggested{
    color: #A9A9A9;
    pointer-events: none;
    white-space: pre;
  }
  &.focus {
    @include box-shadow(0 0 1vw rgba(81, 203, 238, 1));
  }
  &:hover {
    cursor: text;
  }
}
              
            
!

JS

              
                if (typeof String.prototype.startsWith != 'function') {
  // startWith checks if the string begins with the string passed in
  String.prototype.startsWith = function (str){
    return this.slice(0, str.length) == str;
  };
}

angular.module('SuggestedQuery', [])
.controller('suggestionInputCtrl', ['$scope', function($scope){
  var knownQueries = ["Alison Cassidy", "Catherine Sinu", "Sherry Mckenna", "Wil Jones", "Adrian Delamico", "Elizabeth Wu", "David Liam", "James Weston","Sherry, Elizabeth & 5 more", "Mobile Strategy", "Visual Design Language and UX", "Group Thread", "Learn UX Strategies", "Weekly UX Sync", "UX Group Thread", "Visual Design spec", "Visual Icon Design Library","design process","visual language", "Alison's Keynote"];
  // unknownQuery set to true during the first loop where no known queries are found, reset when newQuery is older than oldQuery
  var unknownQuery = false;
  var remainingKnown = function(newQuery){
    for(var i = 0, x = knownQueries.length; i < x; i++){
      if(knownQueries[i].startsWith(newQuery)){
        return knownQueries[i].substring(newQuery.length);
      }
    }
    unknownQuery = true;
    return '';
  };
  $scope.inputQuery = '';
  $scope.$watch(function(){
    return $scope.inputQuery;
  }, function(newQuery, oldQuery){
    if(newQuery.length < oldQuery.length){
      unknownQuery = false;
    }
    
    if(newQuery.length > 0){
      if(!unknownQuery){
         $scope.suggestedQuery = remainingKnown(newQuery);
        console.log($scope.suggestedQuery);
      }
    } else {
      $scope.suggestedQuery = 'Type something here!';
    }
    
  }, false);
  $scope.editInput = function(){
    $scope.$broadcast('editQuery');
  };
}])
.directive('contenteditable', function(){
  return {
    restrict: 'A',
    link: function(scope, element, attrs){
      
      var read = function(){     
        // TODO: reads the element html, then sets the value to inputQuery
        scope.inputQuery = element.html();
      };
      var clearSuggestion = function(){
        scope.suggestedQuery = scope.suggestedQuery.substring(1);
//         scope.suggestedQuery = '';
      };
     
      element.bind('blur keyup change', function(e){
        if(e.keyCode == 39){
          // if you click the right arrow, fill the rest with the suggested query
          scope.inputQuery += scope.suggestedQuery;
        element.html(scope.inputQuery);
          scope.suggestedQuery = '';
        } else {
          read();
        }
        scope.$apply();
      });
      element.bind('blur', function(){
        scope.$apply(function(){
          scope.isFocused = false;
        });
      });
      element.bind('keydown', function(e){
        
        if(e.keyCode == 13){
          // prevent default enter button
          e.preventDefault();
          return;
        } else if(e.keyCode == 37 || e.keyCode == 39 || e.keyCode == 16 || e.keyCode == 8) {
          // 37 is left arrow, 39 right arrow
          
        } else {
          scope.$apply(clearSuggestion);
        }
      });
      scope.$on('editQuery', function(){
        element[0].focus();
      });
      
    }
  }
});
              
            
!
999px

Console